Mercurial > dropbear
comparison src/pk/pkcs1/pkcs_1_pss_encode.c @ 210:4768b55c5240 libtomcrypt
propagate from branch 'au.asn.ucc.matt.ltc-orig' (head 33c416b902f1a44913d825bae7ad9a160f703ed3)
to branch 'au.asn.ucc.matt.dropbear.ltc' (head 4d6aec6e6121e13f68c11c149b6579c41cb63e74)
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 06 Jul 2005 12:10:23 +0000 |
parents | 39d5d58461d6 |
children |
comparison
equal
deleted
inserted
replaced
199:8be64e2c86f4 | 210:4768b55c5240 |
---|---|
108 if ((err = hash_descriptor[hash_idx].done(&md, hash)) != CRYPT_OK) { | 108 if ((err = hash_descriptor[hash_idx].done(&md, hash)) != CRYPT_OK) { |
109 goto LBL_ERR; | 109 goto LBL_ERR; |
110 } | 110 } |
111 | 111 |
112 /* generate DB = PS || 0x01 || salt, PS == modulus_len - saltlen - hLen - 2 zero bytes */ | 112 /* generate DB = PS || 0x01 || salt, PS == modulus_len - saltlen - hLen - 2 zero bytes */ |
113 for (x = 0; x < (modulus_len - saltlen - hLen - 2); x++) { | 113 x = 0; |
114 DB[x] = 0x00; | 114 XMEMSET(DB + x, 0, modulus_len - saltlen - hLen - 2); |
115 } | 115 x += modulus_len - saltlen - hLen - 2; |
116 DB[x++] = 0x01; | 116 DB[x++] = 0x01; |
117 for (y = 0; y < saltlen; y++) { | 117 XMEMCPY(DB + x, salt, saltlen); |
118 DB[x++] = salt[y]; | 118 x += saltlen; |
119 } | |
120 | 119 |
121 /* generate mask of length modulus_len - hLen - 1 from hash */ | 120 /* generate mask of length modulus_len - hLen - 1 from hash */ |
122 if ((err = pkcs_1_mgf1(hash, hLen, hash_idx, mask, modulus_len - hLen - 1)) != CRYPT_OK) { | 121 if ((err = pkcs_1_mgf1(hash, hLen, hash_idx, mask, modulus_len - hLen - 1)) != CRYPT_OK) { |
123 goto LBL_ERR; | 122 goto LBL_ERR; |
124 } | 123 } |
132 if (*outlen < modulus_len) { | 131 if (*outlen < modulus_len) { |
133 err = CRYPT_BUFFER_OVERFLOW; | 132 err = CRYPT_BUFFER_OVERFLOW; |
134 goto LBL_ERR; | 133 goto LBL_ERR; |
135 } | 134 } |
136 | 135 |
137 /* DB */ | 136 /* DB len = modulus_len - hLen - 1 */ |
138 for (y = x = 0; x < modulus_len - hLen - 1; x++) { | 137 y = 0; |
139 out[y++] = DB[x]; | 138 XMEMCPY(out + y, DB, modulus_len - hLen - 1); |
140 } | 139 y += modulus_len - hLen - 1; |
140 | |
141 /* hash */ | 141 /* hash */ |
142 for (x = 0; x < hLen; x++) { | 142 XMEMCPY(out + y, hash, hLen); |
143 out[y++] = hash[x]; | 143 y += hLen; |
144 } | 144 |
145 /* 0xBC */ | 145 /* 0xBC */ |
146 out[y] = 0xBC; | 146 out[y] = 0xBC; |
147 | 147 |
148 /* now clear the 8*modulus_len - modulus_bitlen most significant bits */ | 148 /* now clear the 8*modulus_len - modulus_bitlen most significant bits */ |
149 out[0] &= 0xFF >> ((modulus_len<<3) - (modulus_bitlen-1)); | 149 out[0] &= 0xFF >> ((modulus_len<<3) - (modulus_bitlen-1)); |
166 | 166 |
167 return err; | 167 return err; |
168 } | 168 } |
169 | 169 |
170 #endif /* PKCS_1 */ | 170 #endif /* PKCS_1 */ |
171 | |
172 /* $Source: /cvs/libtom/libtomcrypt/src/pk/pkcs1/pkcs_1_pss_encode.c,v $ */ | |
173 /* $Revision: 1.4 $ */ | |
174 /* $Date: 2005/05/05 14:35:59 $ */ |