Mercurial > dropbear
comparison src/pk/pkcs1/pkcs_1_oaep_encode.c @ 209:39d5d58461d6 libtomcrypt-orig LTC_1.05
Import of libtomcrypt 1.05
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 06 Jul 2005 03:53:40 +0000 |
parents | 1c15b283127b |
children |
comparison
equal
deleted
inserted
replaced
191:1c15b283127b | 209:39d5d58461d6 |
---|---|
64 } | 64 } |
65 | 65 |
66 /* allocate ram for DB/mask/salt of size modulus_len */ | 66 /* allocate ram for DB/mask/salt of size modulus_len */ |
67 DB = XMALLOC(modulus_len); | 67 DB = XMALLOC(modulus_len); |
68 mask = XMALLOC(modulus_len); | 68 mask = XMALLOC(modulus_len); |
69 seed = XMALLOC(modulus_len); | 69 seed = XMALLOC(hLen); |
70 if (DB == NULL || mask == NULL || seed == NULL) { | 70 if (DB == NULL || mask == NULL || seed == NULL) { |
71 if (DB != NULL) { | 71 if (DB != NULL) { |
72 XFREE(DB); | 72 XFREE(DB); |
73 } | 73 } |
74 if (mask != NULL) { | 74 if (mask != NULL) { |
95 } | 95 } |
96 | 96 |
97 /* append PS then 0x01 (to lhash) */ | 97 /* append PS then 0x01 (to lhash) */ |
98 x = hLen; | 98 x = hLen; |
99 y = modulus_len - msglen - 2*hLen - 2; | 99 y = modulus_len - msglen - 2*hLen - 2; |
100 while (y--) { | 100 XMEMSET(DB+x, 0, y); |
101 DB[x++] = 0x00; | 101 x += y; |
102 } | 102 |
103 /* 0x01 byte */ | |
103 DB[x++] = 0x01; | 104 DB[x++] = 0x01; |
104 | 105 |
105 /* message */ | 106 /* message (length = msglen) */ |
106 y = msglen; | 107 XMEMCPY(DB+x, msg, msglen); |
107 while (y--) { | 108 x += msglen; |
108 DB[x++] = *msg++; | |
109 } | |
110 | 109 |
111 /* now choose a random seed */ | 110 /* now choose a random seed */ |
112 if (prng_descriptor[prng_idx].read(seed, hLen, prng) != hLen) { | 111 if (prng_descriptor[prng_idx].read(seed, hLen, prng) != hLen) { |
113 err = CRYPT_ERROR_READPRNG; | 112 err = CRYPT_ERROR_READPRNG; |
114 goto LBL_ERR; | 113 goto LBL_ERR; |
141 } | 140 } |
142 | 141 |
143 /* start output which is 0x00 || maskedSeed || maskedDB */ | 142 /* start output which is 0x00 || maskedSeed || maskedDB */ |
144 x = 0; | 143 x = 0; |
145 out[x++] = 0x00; | 144 out[x++] = 0x00; |
146 for (y = 0; y < hLen; y++) { | 145 XMEMCPY(out+x, seed, hLen); |
147 out[x++] = seed[y]; | 146 x += hLen; |
148 } | 147 XMEMCPY(out+x, DB, modulus_len - hLen - 1); |
149 for (y = 0; y < modulus_len - hLen - 1; y++) { | 148 x += modulus_len - hLen - 1; |
150 out[x++] = DB[y]; | 149 |
151 } | |
152 *outlen = x; | 150 *outlen = x; |
153 | 151 |
154 err = CRYPT_OK; | 152 err = CRYPT_OK; |
155 LBL_ERR: | 153 LBL_ERR: |
156 #ifdef LTC_CLEAN_STACK | 154 #ifdef LTC_CLEAN_STACK |
157 zeromem(DB, modulus_len); | 155 zeromem(DB, modulus_len); |
158 zeromem(seed, modulus_len); | 156 zeromem(seed, hLen); |
159 zeromem(mask, modulus_len); | 157 zeromem(mask, modulus_len); |
160 #endif | 158 #endif |
161 | 159 |
162 XFREE(seed); | 160 XFREE(seed); |
163 XFREE(mask); | 161 XFREE(mask); |
166 return err; | 164 return err; |
167 } | 165 } |
168 | 166 |
169 #endif /* PKCS_1 */ | 167 #endif /* PKCS_1 */ |
170 | 168 |
169 | |
170 /* $Source: /cvs/libtom/libtomcrypt/src/pk/pkcs1/pkcs_1_oaep_encode.c,v $ */ | |
171 /* $Revision: 1.4 $ */ | |
172 /* $Date: 2005/05/05 14:35:59 $ */ |