Bonjour à tous,
dans le cadre de mon projet de fin d'étude, je teste la bibliothèque Bouncycastle sur les chiffrements symétriques et asymétrique, afin de savoir si elle est conforme au document RFC PKCS1.
Je dois commencer avec le padding EMSA et pour ce faire, tester tous les points de 1 à 5.
Le premier point étant que le message est haché par une fonction de hachage et doit renvoyer un message d'erreur au cas où le message M serait trop long, si j'ai bien compris.
Je dois tester avec une fonction de hachage et j'ai choisi SHA-1.
Mon problème est que je n'arrive pas à hacher un message avec la fonction SHA1Digest du Bouncycastle.
Comment tester le point 1 et 2?
Est ce que j' utilise la bonne méthode?
9.2 EMSA-PKCS1-v1_5
This encoding method is deterministic and only has an encoding
operation.
EMSA-PKCS1-v1_5-ENCODE (M, emLen)
Option:
Hash hash function (hLen denotes the length in octets of the hash
function output)
Input:
M message to be encoded
emLen intended length in octets of the encoded message, at least
tLen + 11, where tLen is the octet length of the DER
encoding T of a certain value computed during the encoding
operation
Output:
EM encoded message, an octet string of length emLen
Errors:
"message too long"; "intended encoded message length too short"
Steps:
1. Apply the hash function to the message M to produce a hash value
H:
H = Hash(M).
If the hash function outputs "message too long," output "message
too long" and stop.
2. Encode the algorithm ID for the hash function and the hash value
into an ASN.1 value of type DigestInfo (see Appendix A.2.4) with
the Distinguished Encoding Rules (DER), where the type DigestInfo
has the syntax
DigestInfo ::= SEQUENCE {
digestAlgorithm AlgorithmIdentifier,
digest OCTET STRING
}
The first field identifies the hash function and the second
contains the hash value. Let T be the DER encoding of the
DigestInfo value (see the notes below) and let tLen be the length
in octets of T.
3. If emLen < tLen + 11, output "intended encoded message length too
short" and stop.
4. Generate an octet string PS consisting of emLen - tLen - 3 octets
with hexadecimal value 0xff. The length of PS will be at least 8
octets.
5. Concatenate PS, the DER encoding T, and other padding to form the
encoded message EM as
EM = 0x00 || 0x01 || PS || 0x00 || T.
6. Output EM.
https://tools.ietf.org/html/rfc3447#section-9.2
J'ai parcouru le forum et je n'ai pas trouvé de solution.
Toute aide est la bienvenue.
Merci
Partager