Mercurial > dropbear
annotate src/pk/pkcs1/pkcs_1_pss_decode.c @ 280:59400faa4b44 libtomcrypt-orig libtomcrypt-1.05
Re-import libtomcrypt 1.05 for cleaner propagating.
From crypt-1.05.tar.bz2, SHA1 of 88250202bb51570dc64f7e8f1c943cda9479258f
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 08 Mar 2006 12:58:00 +0000 |
parents | |
children | d5faf4814ddb |
rev | line source |
---|---|
280
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
2 * |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
3 * LibTomCrypt is a library that provides various cryptographic |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
4 * algorithms in a highly modular and flexible manner. |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
5 * |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
6 * The library is free for all purposes without any express |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
7 * guarantee it works. |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
8 * |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
9 * Tom St Denis, [email protected], http://libtomcrypt.org |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
10 */ |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
11 #include "tomcrypt.h" |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
12 |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
13 /** |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
14 @file pkcs_1_pss_decode.c |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
15 PKCS #1 PSS Signature Padding, Tom St Denis |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
16 */ |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
17 |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
18 #ifdef PKCS_1 |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
19 |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
20 /** |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
21 PKCS #1 v2.00 PSS decode |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
22 @param msghash The hash to verify |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
23 @param msghashlen The length of the hash (octets) |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
24 @param sig The signature data (encoded data) |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
25 @param siglen The length of the signature data (octets) |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
26 @param saltlen The length of the salt used (octets) |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
27 @param hash_idx The index of the hash desired |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
28 @param modulus_bitlen The bit length of the RSA modulus |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
29 @param res [out] The result of the comparison, 1==valid, 0==invalid |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
30 @return CRYPT_OK if successful (even if the comparison failed) |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
31 */ |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
32 int pkcs_1_pss_decode(const unsigned char *msghash, unsigned long msghashlen, |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
33 const unsigned char *sig, unsigned long siglen, |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
34 unsigned long saltlen, int hash_idx, |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
35 unsigned long modulus_bitlen, int *res) |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
36 { |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
37 unsigned char *DB, *mask, *salt, *hash; |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
38 unsigned long x, y, hLen, modulus_len; |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
39 int err; |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
40 hash_state md; |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
41 |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
42 LTC_ARGCHK(msghash != NULL); |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
43 LTC_ARGCHK(res != NULL); |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
44 |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
45 /* default to invalid */ |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
46 *res = 0; |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
47 |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
48 /* ensure hash is valid */ |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
49 if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) { |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
50 return err; |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
51 } |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
52 |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
53 hLen = hash_descriptor[hash_idx].hashsize; |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
54 modulus_len = (modulus_bitlen>>3) + (modulus_bitlen & 7 ? 1 : 0); |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
55 |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
56 /* check sizes */ |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
57 if ((saltlen > modulus_len) || |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
58 (modulus_len < hLen + saltlen + 2) || (siglen != modulus_len)) { |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
59 return CRYPT_PK_INVALID_SIZE; |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
60 } |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
61 |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
62 /* allocate ram for DB/mask/salt/hash of size modulus_len */ |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
63 DB = XMALLOC(modulus_len); |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
64 mask = XMALLOC(modulus_len); |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
65 salt = XMALLOC(modulus_len); |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
66 hash = XMALLOC(modulus_len); |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
67 if (DB == NULL || mask == NULL || salt == NULL || hash == NULL) { |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
68 if (DB != NULL) { |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
69 XFREE(DB); |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
70 } |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
71 if (mask != NULL) { |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
72 XFREE(mask); |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
73 } |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
74 if (salt != NULL) { |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
75 XFREE(salt); |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
76 } |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
77 if (hash != NULL) { |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
78 XFREE(hash); |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
79 } |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
80 return CRYPT_MEM; |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
81 } |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
82 |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
83 /* ensure the 0xBC byte */ |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
84 if (sig[siglen-1] != 0xBC) { |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
85 err = CRYPT_OK; |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
86 goto LBL_ERR; |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
87 } |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
88 |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
89 /* copy out the DB */ |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
90 x = 0; |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
91 XMEMCPY(DB, sig + x, modulus_len - hLen - 1); |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
92 x += modulus_len - hLen - 1; |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
93 |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
94 /* copy out the hash */ |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
95 XMEMCPY(hash, sig + x, hLen); |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
96 x += hLen; |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
97 |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
98 /* check the MSB */ |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
99 if ((sig[0] & ~(0xFF >> ((modulus_len<<3) - (modulus_bitlen-1)))) != 0) { |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
100 err = CRYPT_OK; |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
101 goto LBL_ERR; |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
102 } |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
103 |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
104 /* generate mask of length modulus_len - hLen - 1 from hash */ |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
105 if ((err = pkcs_1_mgf1(hash, hLen, hash_idx, mask, modulus_len - hLen - 1)) != CRYPT_OK) { |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
106 goto LBL_ERR; |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
107 } |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
108 |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
109 /* xor against DB */ |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
110 for (y = 0; y < (modulus_len - hLen - 1); y++) { |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
111 DB[y] ^= mask[y]; |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
112 } |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
113 |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
114 /* now clear the first byte [make sure smaller than modulus] */ |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
115 DB[0] &= 0xFF >> ((modulus_len<<3) - (modulus_bitlen-1)); |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
116 |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
117 /* DB = PS || 0x01 || salt, PS == modulus_len - saltlen - hLen - 2 zero bytes */ |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
118 |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
119 /* check for zeroes and 0x01 */ |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
120 for (x = 0; x < modulus_len - saltlen - hLen - 2; x++) { |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
121 if (DB[x] != 0x00) { |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
122 err = CRYPT_OK; |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
123 goto LBL_ERR; |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
124 } |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
125 } |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
126 |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
127 /* check for the 0x01 */ |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
128 if (DB[x++] != 0x01) { |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
129 err = CRYPT_OK; |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
130 goto LBL_ERR; |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
131 } |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
132 |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
133 /* M = (eight) 0x00 || msghash || salt, mask = H(M) */ |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
134 if ((err = hash_descriptor[hash_idx].init(&md)) != CRYPT_OK) { |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
135 goto LBL_ERR; |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
136 } |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
137 zeromem(mask, 8); |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
138 if ((err = hash_descriptor[hash_idx].process(&md, mask, 8)) != CRYPT_OK) { |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
139 goto LBL_ERR; |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
140 } |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
141 if ((err = hash_descriptor[hash_idx].process(&md, msghash, msghashlen)) != CRYPT_OK) { |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
142 goto LBL_ERR; |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
143 } |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
144 if ((err = hash_descriptor[hash_idx].process(&md, DB+x, saltlen)) != CRYPT_OK) { |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
145 goto LBL_ERR; |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
146 } |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
147 if ((err = hash_descriptor[hash_idx].done(&md, mask)) != CRYPT_OK) { |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
148 goto LBL_ERR; |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
149 } |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
150 |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
151 /* mask == hash means valid signature */ |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
152 if (memcmp(mask, hash, hLen) == 0) { |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
153 *res = 1; |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
154 } |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
155 |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
156 err = CRYPT_OK; |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
157 LBL_ERR: |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
158 #ifdef LTC_CLEAN_STACK |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
159 zeromem(DB, modulus_len); |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
160 zeromem(mask, modulus_len); |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
161 zeromem(salt, modulus_len); |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
162 zeromem(hash, modulus_len); |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
163 #endif |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
164 |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
165 XFREE(hash); |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
166 XFREE(salt); |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
167 XFREE(mask); |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
168 XFREE(DB); |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
169 |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
170 return err; |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
171 } |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
172 |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
173 #endif /* PKCS_1 */ |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
174 |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
175 /* $Source: /cvs/libtom/libtomcrypt/src/pk/pkcs1/pkcs_1_pss_decode.c,v $ */ |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
176 /* $Revision: 1.4 $ */ |
59400faa4b44
Re-import libtomcrypt 1.05 for cleaner propagating.
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
177 /* $Date: 2005/05/05 14:35:59 $ */ |