Package list libcryptx-perl / 2a90bfe
ltc update Karel Miko 3 years ago
92 changed file(s) with 516 addition(s) and 394 deletion(s). Raw diff Collapse all Expand all
280280 @return CRYPT_OK if successful
281281 */
282282 #ifdef LTC_CLEAN_STACK
283 static int _rijndael_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
283 static int _rijndael_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
284284 #else
285 int ECB_ENC(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
286 #endif
287 {
288 ulong32 s0, s1, s2, s3, t0, t1, t2, t3, *rk;
285 int ECB_ENC(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
286 #endif
287 {
288 ulong32 s0, s1, s2, s3, t0, t1, t2, t3;
289 const ulong32 *rk;
289290 int Nr, r;
290291
291292 LTC_ARGCHK(pt != NULL);
441442 }
442443
443444 #ifdef LTC_CLEAN_STACK
444 int ECB_ENC(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
445 int ECB_ENC(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
445446 {
446447 int err = _rijndael_ecb_encrypt(pt, ct, skey);
447448 burn_stack(sizeof(unsigned long)*8 + sizeof(unsigned long*) + sizeof(int)*2);
459460 @return CRYPT_OK if successful
460461 */
461462 #ifdef LTC_CLEAN_STACK
462 static int _rijndael_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
463 static int _rijndael_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
463464 #else
464 int ECB_DEC(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
465 #endif
466 {
467 ulong32 s0, s1, s2, s3, t0, t1, t2, t3, *rk;
465 int ECB_DEC(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
466 #endif
467 {
468 ulong32 s0, s1, s2, s3, t0, t1, t2, t3;
469 const ulong32 *rk;
468470 int Nr, r;
469471
470472 LTC_ARGCHK(pt != NULL);
621623
622624
623625 #ifdef LTC_CLEAN_STACK
624 int ECB_DEC(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
626 int ECB_DEC(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
625627 {
626628 int err = _rijndael_ecb_decrypt(ct, pt, skey);
627629 burn_stack(sizeof(unsigned long)*8 + sizeof(unsigned long*) + sizeof(int)*2);
9393 0x7bb0b0cbUL, 0xa85454fcUL, 0x6dbbbbd6UL, 0x2c16163aUL,
9494 };
9595
96 #ifndef PELI_TAB
96 #if !defined(PELI_TAB) && defined(LTC_SMALL_CODE)
9797 static const ulong32 Te4[256] = {
9898 0x63636363UL, 0x7c7c7c7cUL, 0x77777777UL, 0x7b7b7b7bUL,
9999 0xf2f2f2f2UL, 0x6b6b6b6bUL, 0x6f6f6f6fUL, 0xc5c5c5c5UL,
10161016
10171017 #endif /* SMALL CODE */
10181018
1019 #ifndef PELI_TAB
10191020 static const ulong32 rcon[] = {
10201021 0x01000000UL, 0x02000000UL, 0x04000000UL, 0x08000000UL,
10211022 0x10000000UL, 0x20000000UL, 0x40000000UL, 0x80000000UL,
10221023 0x1B000000UL, 0x36000000UL, /* for 128-bit blocks, Rijndael never uses more than 10 rcon values */
10231024 };
1025 #endif
10241026
10251027 #endif /* __LTC_AES_TAB_C__ */
10261028
10341034
10351035
10361036 static void anubis_crypt(const unsigned char *plaintext, unsigned char *ciphertext,
1037 ulong32 roundKey[18 + 1][4], int R) {
1037 const ulong32 roundKey[18 + 1][4], int R) {
10381038 int i, pos, r;
10391039 ulong32 state[4];
10401040 ulong32 inter[4];
11331133 @param skey The key as scheduled
11341134 @return CRYPT_OK if successful
11351135 */
1136 int anubis_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
1136 int anubis_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
11371137 {
11381138 LTC_ARGCHK(pt != NULL);
11391139 LTC_ARGCHK(ct != NULL);
11491149 @param skey The key as scheduled
11501150 @return CRYPT_OK if successful
11511151 */
1152 int anubis_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
1152 int anubis_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
11531153 {
11541154 LTC_ARGCHK(pt != NULL);
11551155 LTC_ARGCHK(ct != NULL);
385385 @return CRYPT_OK if successful
386386 */
387387 #ifdef LTC_CLEAN_STACK
388 static int _blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
388 static int _blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
389389 #else
390 int blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
390 int blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
391391 #endif
392392 {
393393 ulong32 L, R;
431431 }
432432
433433 #ifdef LTC_CLEAN_STACK
434 int blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
434 int blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
435435 {
436436 int err = _blowfish_ecb_encrypt(pt, ct, skey);
437437 burn_stack(sizeof(ulong32) * 2 + sizeof(int));
447447 @return CRYPT_OK if successful
448448 */
449449 #ifdef LTC_CLEAN_STACK
450 static int _blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
450 static int _blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
451451 #else
452 int blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
452 int blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
453453 #endif
454454 {
455455 ulong32 L, R;
492492 }
493493
494494 #ifdef LTC_CLEAN_STACK
495 int blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
495 int blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
496496 {
497497 int err = _blowfish_ecb_decrypt(ct, pt, skey);
498498 burn_stack(sizeof(ulong32) * 2 + sizeof(int));
192192 return ((ulong64)U) | (((ulong64)D) << CONST64(32));
193193 }
194194
195 static void rot_128(unsigned char *in, unsigned count, unsigned char *out)
195 static void rot_128(const unsigned char *in, unsigned count, unsigned char *out)
196196 {
197197 unsigned x, w, b;
198198
435435 return CRYPT_OK;
436436 }
437437
438 int camellia_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
438 int camellia_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
439439 {
440440 ulong64 L, R;
441441 ulong32 a, b;
529529 return CRYPT_OK;
530530 }
531531
532 int camellia_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
532 int camellia_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
533533 {
534534 ulong64 L, R;
535535 ulong32 a, b;
533533 @param skey The key as scheduled
534534 */
535535 #ifdef LTC_CLEAN_STACK
536 static int _cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
536 static int _cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
537537 #else
538 int cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
538 int cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
539539 #endif
540540 {
541541 ulong32 R, L;
571571
572572
573573 #ifdef LTC_CLEAN_STACK
574 int cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
574 int cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
575575 {
576576 int err =_cast5_ecb_encrypt(pt,ct,skey);
577577 burn_stack(sizeof(ulong32)*3);
586586 @param skey The key as scheduled
587587 */
588588 #ifdef LTC_CLEAN_STACK
589 static int _cast5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
589 static int _cast5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
590590 #else
591 int cast5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
591 int cast5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
592592 #endif
593593 {
594594 ulong32 R, L;
624624 }
625625
626626 #ifdef LTC_CLEAN_STACK
627 int cast5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
627 int cast5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
628628 {
629629 int err = _cast5_ecb_decrypt(ct,pt,skey);
630630 burn_stack(sizeof(ulong32)*3);
15911591 @param skey The key as scheduled
15921592 @return CRYPT_OK if successful
15931593 */
1594 int des_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
1594 int des_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
15951595 {
15961596 ulong32 work[2];
15971597 LTC_ARGCHK(pt != NULL);
16121612 @param skey The key as scheduled
16131613 @return CRYPT_OK if successful
16141614 */
1615 int des_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
1615 int des_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
16161616 {
16171617 ulong32 work[2];
16181618 LTC_ARGCHK(pt != NULL);
16331633 @param skey The key as scheduled
16341634 @return CRYPT_OK if successful
16351635 */
1636 int des3_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
1636 int des3_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
16371637 {
16381638 ulong32 work[2];
16391639
16571657 @param skey The key as scheduled
16581658 @return CRYPT_OK if successful
16591659 */
1660 int des3_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
1660 int des3_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
16611661 {
16621662 ulong32 work[2];
16631663 LTC_ARGCHK(pt != NULL);
103103 return CRYPT_OK;
104104 }
105105
106 static int _process_block(const unsigned char *in, unsigned char *out, ushort16 *m_key)
106 static int _process_block(const unsigned char *in, unsigned char *out, const ushort16 *m_key)
107107 {
108108 int i;
109109 ushort16 x0, x1, x2, x3, t0, t1;
154154 return _setup_key(key, skey);
155155 }
156156
157 int idea_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
157 int idea_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
158158 {
159159 int err = _process_block(pt, ct, skey->idea.ek);
160160 #ifdef LTC_CLEAN_STACK
163163 return err;
164164 }
165165
166 int idea_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
166 int idea_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
167167 {
168168 int err = _process_block(ct, pt, skey->idea.dk);
169169 #ifdef LTC_CLEAN_STACK
9595 return (u16)(seven<<9) + nine;
9696 }
9797
98 static ulong32 FO( ulong32 in, int round_no, symmetric_key *key)
98 static ulong32 FO( ulong32 in, int round_no, const symmetric_key *key)
9999 {
100100 u16 left, right;
101101
119119 return (((ulong32)right)<<16)+left;
120120 }
121121
122 static ulong32 FL( ulong32 in, int round_no, symmetric_key *key )
122 static ulong32 FL( ulong32 in, int round_no, const symmetric_key *key )
123123 {
124124 u16 l, r, a, b;
125125 /* split out the left and right halves */
135135 return (((ulong32)l)<<16) + r;
136136 }
137137
138 int kasumi_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
138 int kasumi_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
139139 {
140140 ulong32 left, right, temp;
141141 int n;
162162 return CRYPT_OK;
163163 }
164164
165 int kasumi_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
165 int kasumi_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
166166 {
167167 ulong32 left, right, temp;
168168 int n;
740740 @param skey The key as scheduled
741741 @return CRYPT_OK if successful
742742 */
743 int khazad_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
743 int khazad_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
744744 {
745745 LTC_ARGCHK(pt != NULL);
746746 LTC_ARGCHK(ct != NULL);
756756 @param skey The key as scheduled
757757 @return CRYPT_OK if successful
758758 */
759 int khazad_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
759 int khazad_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
760760 {
761761 LTC_ARGCHK(pt != NULL);
762762 LTC_ARGCHK(ct != NULL);
235235 return CRYPT_OK;
236236 }
237237
238 static void rounds(ulong32 *P, ulong32 *K)
238 static void rounds(ulong32 *P, const ulong32 *K)
239239 {
240240 ulong32 T, T2;
241241 int i;
253253 @param skey The key as scheduled
254254 @return CRYPT_OK if successful
255255 */
256 int kseed_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
256 int kseed_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
257257 {
258258 ulong32 P[4];
259259 LOAD32H(P[0], pt);
275275 @param skey The key as scheduled
276276 @return CRYPT_OK if successful
277277 */
278 int kseed_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
278 int kseed_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
279279 {
280280 ulong32 P[4];
281281 LOAD32H(P[0], ct);
1919 p[1] ^= p[0];
2020 }
2121
22 static void pi2(ulong32 *p, ulong32 *k)
22 static void pi2(ulong32 *p, const ulong32 *k)
2323 {
2424 ulong32 t;
2525 t = (p[1] + k[0]) & 0xFFFFFFFFUL;
2828 p[0] ^= t;
2929 }
3030
31 static void pi3(ulong32 *p, ulong32 *k)
31 static void pi3(ulong32 *p, const ulong32 *k)
3232 {
3333 ulong32 t;
3434 t = p[0] + k[1];
4040 p[1] ^= t;
4141 }
4242
43 static void pi4(ulong32 *p, ulong32 *k)
43 static void pi4(ulong32 *p, const ulong32 *k)
4444 {
4545 ulong32 t;
4646 t = (p[1] + k[3]) & 0xFFFFFFFFUL;
4848 p[0] ^= t;
4949 }
5050
51 static void setup(ulong32 *dk, ulong32 *k, ulong32 *uk)
51 static void setup(const ulong32 *dk, const ulong32 *k, ulong32 *uk)
5252 {
5353 int n, t;
5454 ulong32 p[2];
7676 uk[n++] = p[1];
7777 }
7878
79 static void encrypt(ulong32 *p, int N, ulong32 *uk)
79 static void encrypt(ulong32 *p, int N, const ulong32 *uk)
8080 {
8181 int n, t;
8282 for (t = n = 0; ; ) {
8888 }
8989 }
9090
91 static void decrypt(ulong32 *p, int N, ulong32 *uk)
91 static void decrypt(ulong32 *p, int N, const ulong32 *uk)
9292 {
9393 int n, t;
9494 for (t = 4*(((N-1)>>2)&1), n = N; ; ) {
147147 @param skey The key as scheduled
148148 @return CRYPT_OK if successful
149149 */
150 int multi2_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
150 int multi2_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
151151 {
152152 ulong32 p[2];
153153 LTC_ARGCHK(pt != NULL);
168168 @param skey The key as scheduled
169169 @return CRYPT_OK if successful
170170 */
171 int multi2_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
171 int multi2_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
172172 {
173173 ulong32 p[2];
174174 LTC_ARGCHK(pt != NULL);
107107 @return CRYPT_OK if successful
108108 */
109109 #ifdef LTC_CLEAN_STACK
110 static int _noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
110 static int _noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
111111 #else
112 int noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
112 int noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
113113 #endif
114114 {
115115 ulong32 a,b,c,d,temp;
145145 }
146146
147147 #ifdef LTC_CLEAN_STACK
148 int noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
148 int noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
149149 {
150150 int err = _noekeon_ecb_encrypt(pt, ct, skey);
151151 burn_stack(sizeof(ulong32) * 5 + sizeof(int));
161161 @return CRYPT_OK if successful
162162 */
163163 #ifdef LTC_CLEAN_STACK
164 static int _noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
164 static int _noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
165165 #else
166 int noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
166 int noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
167167 #endif
168168 {
169169 ulong32 a,b,c,d, temp;
198198 }
199199
200200 #ifdef LTC_CLEAN_STACK
201 int noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
201 int noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
202202 {
203203 int err = _noekeon_ecb_decrypt(ct, pt, skey);
204204 burn_stack(sizeof(ulong32) * 5 + sizeof(int));
146146 #ifdef LTC_CLEAN_STACK
147147 static int _rc2_ecb_encrypt( const unsigned char *pt,
148148 unsigned char *ct,
149 symmetric_key *skey)
149 const symmetric_key *skey)
150150 #else
151151 int rc2_ecb_encrypt( const unsigned char *pt,
152152 unsigned char *ct,
153 symmetric_key *skey)
154 #endif
155 {
156 unsigned *xkey;
153 const symmetric_key *skey)
154 #endif
155 {
156 const unsigned *xkey;
157157 unsigned x76, x54, x32, x10, i;
158158
159159 LTC_ARGCHK(pt != NULL);
203203 #ifdef LTC_CLEAN_STACK
204204 int rc2_ecb_encrypt( const unsigned char *pt,
205205 unsigned char *ct,
206 symmetric_key *skey)
206 const symmetric_key *skey)
207207 {
208208 int err = _rc2_ecb_encrypt(pt, ct, skey);
209209 burn_stack(sizeof(unsigned *) + sizeof(unsigned) * 5);
224224 #ifdef LTC_CLEAN_STACK
225225 static int _rc2_ecb_decrypt( const unsigned char *ct,
226226 unsigned char *pt,
227 symmetric_key *skey)
227 const symmetric_key *skey)
228228 #else
229229 int rc2_ecb_decrypt( const unsigned char *ct,
230230 unsigned char *pt,
231 symmetric_key *skey)
231 const symmetric_key *skey)
232232 #endif
233233 {
234234 unsigned x76, x54, x32, x10;
235 unsigned *xkey;
235 const unsigned *xkey;
236236 int i;
237237
238238 LTC_ARGCHK(pt != NULL);
282282 #ifdef LTC_CLEAN_STACK
283283 int rc2_ecb_decrypt( const unsigned char *ct,
284284 unsigned char *pt,
285 symmetric_key *skey)
285 const symmetric_key *skey)
286286 {
287287 int err = _rc2_ecb_decrypt(ct, pt, skey);
288288 burn_stack(sizeof(unsigned *) + sizeof(unsigned) * 4 + sizeof(int));
123123 @return CRYPT_OK if successful
124124 */
125125 #ifdef LTC_CLEAN_STACK
126 static int _rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
126 static int _rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
127127 #else
128 int rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
129 #endif
130 {
131 ulong32 A, B, *K;
128 int rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
129 #endif
130 {
131 ulong32 A, B;
132 const ulong32 *K;
132133 int r;
133134 LTC_ARGCHK(skey != NULL);
134135 LTC_ARGCHK(pt != NULL);
162163 }
163164
164165 #ifdef LTC_CLEAN_STACK
165 int rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
166 int rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
166167 {
167168 int err = _rc5_ecb_encrypt(pt, ct, skey);
168169 burn_stack(sizeof(ulong32) * 2 + sizeof(int));
178179 @return CRYPT_OK if successful
179180 */
180181 #ifdef LTC_CLEAN_STACK
181 static int _rc5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
182 static int _rc5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
182183 #else
183 int rc5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
184 #endif
185 {
186 ulong32 A, B, *K;
184 int rc5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
185 #endif
186 {
187 ulong32 A, B;
188 const ulong32 *K;
187189 int r;
188190 LTC_ARGCHK(skey != NULL);
189191 LTC_ARGCHK(pt != NULL);
218220 }
219221
220222 #ifdef LTC_CLEAN_STACK
221 int rc5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
223 int rc5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
222224 {
223225 int err = _rc5_ecb_decrypt(ct, pt, skey);
224226 burn_stack(sizeof(ulong32) * 2 + sizeof(int));
117117 @param skey The key as scheduled
118118 */
119119 #ifdef LTC_CLEAN_STACK
120 static int _rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
120 static int _rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
121121 #else
122 int rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
123 #endif
124 {
125 ulong32 a,b,c,d,t,u, *K;
122 int rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
123 #endif
124 {
125 ulong32 a,b,c,d,t,u;
126 const ulong32 *K;
126127 int r;
127128
128129 LTC_ARGCHK(skey != NULL);
156157 }
157158
158159 #ifdef LTC_CLEAN_STACK
159 int rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
160 int rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
160161 {
161162 int err = _rc6_ecb_encrypt(pt, ct, skey);
162163 burn_stack(sizeof(ulong32) * 6 + sizeof(int));
171172 @param skey The key as scheduled
172173 */
173174 #ifdef LTC_CLEAN_STACK
174 static int _rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
175 static int _rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
175176 #else
176 int rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
177 #endif
178 {
179 ulong32 a,b,c,d,t,u, *K;
177 int rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
178 #endif
179 {
180 ulong32 a,b,c,d,t,u;
181 const ulong32 *K;
180182 int r;
181183
182184 LTC_ARGCHK(skey != NULL);
212214 }
213215
214216 #ifdef LTC_CLEAN_STACK
215 int rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
217 int rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
216218 {
217219 int err = _rc6_ecb_decrypt(ct, pt, skey);
218220 burn_stack(sizeof(ulong32) * 6 + sizeof(int));
246246 #ifdef LTC_CLEAN_STACK
247247 static int _safer_ecb_encrypt(const unsigned char *block_in,
248248 unsigned char *block_out,
249 symmetric_key *skey)
249 const symmetric_key *skey)
250250 #else
251251 int safer_ecb_encrypt(const unsigned char *block_in,
252252 unsigned char *block_out,
253 symmetric_key *skey)
253 const symmetric_key *skey)
254254 #endif
255255 { unsigned char a, b, c, d, e, f, g, h, t;
256256 unsigned int round;
257 unsigned char *key;
257 const unsigned char *key;
258258
259259 LTC_ARGCHK(block_in != NULL);
260260 LTC_ARGCHK(block_out != NULL);
289289 #ifdef LTC_CLEAN_STACK
290290 int safer_ecb_encrypt(const unsigned char *block_in,
291291 unsigned char *block_out,
292 symmetric_key *skey)
292 const symmetric_key *skey)
293293 {
294294 int err = _safer_ecb_encrypt(block_in, block_out, skey);
295295 burn_stack(sizeof(unsigned char) * 9 + sizeof(unsigned int) + sizeof(unsigned char *));
300300 #ifdef LTC_CLEAN_STACK
301301 static int _safer_ecb_decrypt(const unsigned char *block_in,
302302 unsigned char *block_out,
303 symmetric_key *skey)
303 const symmetric_key *skey)
304304 #else
305305 int safer_ecb_decrypt(const unsigned char *block_in,
306306 unsigned char *block_out,
307 symmetric_key *skey)
307 const symmetric_key *skey)
308308 #endif
309309 { unsigned char a, b, c, d, e, f, g, h, t;
310310 unsigned int round;
311 unsigned char *key;
311 const unsigned char *key;
312312
313313 LTC_ARGCHK(block_in != NULL);
314314 LTC_ARGCHK(block_out != NULL);
344344 #ifdef LTC_CLEAN_STACK
345345 int safer_ecb_decrypt(const unsigned char *block_in,
346346 unsigned char *block_out,
347 symmetric_key *skey)
347 const symmetric_key *skey)
348348 {
349349 int err = _safer_ecb_decrypt(block_in, block_out, skey);
350350 burn_stack(sizeof(unsigned char) * 9 + sizeof(unsigned int) + sizeof(unsigned char *));
142142
143143 #ifdef LTC_SMALL_CODE
144144
145 static void _round(unsigned char *b, int i, symmetric_key *skey)
145 static void _round(unsigned char *b, int i, const symmetric_key *skey)
146146 {
147147 ROUND(b, i);
148148 }
149149
150 static void _iround(unsigned char *b, int i, symmetric_key *skey)
150 static void _iround(unsigned char *b, int i, const symmetric_key *skey)
151151 {
152152 iROUND(b, i);
153153 }
337337 @param skey The key as scheduled
338338 @return CRYPT_OK if successful
339339 */
340 int saferp_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
340 int saferp_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
341341 {
342342 unsigned char b[16];
343343 int x;
401401 @param skey The key as scheduled
402402 @return CRYPT_OK if successful
403403 */
404 int saferp_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
404 int saferp_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
405405 {
406406 unsigned char b[16];
407407 int x;
487487 return CRYPT_OK;
488488 }
489489
490 static int _enc_block(const unsigned char *in, unsigned char *out, ulong32 *k)
490 static int _enc_block(const unsigned char *in, unsigned char *out, const ulong32 *k)
491491 {
492492 ulong32 a, b, c, d, e;
493493 unsigned int i = 1;
529529 return CRYPT_OK;
530530 }
531531
532 static int _dec_block(const unsigned char *in, unsigned char *out, ulong32 *k)
532 static int _dec_block(const unsigned char *in, unsigned char *out, const ulong32 *k)
533533 {
534534 ulong32 a, b, c, d, e;
535535 unsigned int i;
587587 return err;
588588 }
589589
590 int serpent_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
590 int serpent_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
591591 {
592592 int err = _enc_block(pt, ct, skey->serpent.k);
593593 #ifdef LTC_CLEAN_STACK
596596 return err;
597597 }
598598
599 int serpent_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
599 int serpent_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
600600 {
601601 int err = _dec_block(ct, pt, skey->serpent.k);
602602 #ifdef LTC_CLEAN_STACK
106106 w2 = tmp ^ w3 ^ x; \
107107 w3 = w4; w4 = w1; w1 = tmp;
108108
109 static unsigned g_func(unsigned w, int *kp, unsigned char *key)
109 static unsigned g_func(unsigned w, int *kp, const unsigned char *key)
110110 {
111111 unsigned char g1,g2;
112112
118118 return ((unsigned)g1<<8)|(unsigned)g2;
119119 }
120120
121 static unsigned ig_func(unsigned w, int *kp, unsigned char *key)
121 static unsigned ig_func(unsigned w, int *kp, const unsigned char *key)
122122 {
123123 unsigned char g1,g2;
124124
138138 @return CRYPT_OK if successful
139139 */
140140 #ifdef LTC_CLEAN_STACK
141 static int _skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
141 static int _skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
142142 #else
143 int skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
143 int skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
144144 #endif
145145 {
146146 unsigned w1,w2,w3,w4,tmp,tmp1;
186186 }
187187
188188 #ifdef LTC_CLEAN_STACK
189 int skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
189 int skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
190190 {
191191 int err = _skipjack_ecb_encrypt(pt, ct, skey);
192192 burn_stack(sizeof(unsigned) * 8 + sizeof(int) * 2);
202202 @return CRYPT_OK if successful
203203 */
204204 #ifdef LTC_CLEAN_STACK
205 static int _skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
205 static int _skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
206206 #else
207 int skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
207 int skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
208208 #endif
209209 {
210210 unsigned w1,w2,w3,w4,tmp;
254254 }
255255
256256 #ifdef LTC_CLEAN_STACK
257 int skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
257 int skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
258258 {
259259 int err = _skipjack_ecb_decrypt(ct, pt, skey);
260260 burn_stack(sizeof(unsigned) * 7 + sizeof(int) * 2);
236236 #endif
237237
238238 /* computes h(x) */
239 static void h_func(const unsigned char *in, unsigned char *out, unsigned char *M, int k, int offset)
239 static void h_func(const unsigned char *in, unsigned char *out, const unsigned char *M, int k, int offset)
240240 {
241241 int x;
242242 unsigned char y[4];
283283 #else
284284
285285 #ifdef LTC_CLEAN_STACK
286 static ulong32 _g_func(ulong32 x, symmetric_key *key)
287 #else
288 static ulong32 g_func(ulong32 x, symmetric_key *key)
286 static ulong32 _g_func(ulong32 x, const symmetric_key *key)
287 #else
288 static ulong32 g_func(ulong32 x, const symmetric_key *key)
289289 #endif
290290 {
291291 unsigned char g, i, y, z;
316316 #define g1_func(x, key) g_func(ROLc(x, 8), key)
317317
318318 #ifdef LTC_CLEAN_STACK
319 static ulong32 g_func(ulong32 x, symmetric_key *key)
319 static ulong32 g_func(ulong32 x, const symmetric_key *key)
320320 {
321321 ulong32 y;
322322 y = _g_func(x, key);
463463 @return CRYPT_OK if successful
464464 */
465465 #ifdef LTC_CLEAN_STACK
466 static int _twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
467 #else
468 int twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
469 #endif
470 {
471 ulong32 a,b,c,d,ta,tb,tc,td,t1,t2, *k;
466 static int _twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
467 #else
468 int twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
469 #endif
470 {
471 ulong32 a,b,c,d,ta,tb,tc,td,t1,t2;
472 const ulong32 *k;
472473 int r;
473474 #if !defined(LTC_TWOFISH_SMALL) && !defined(__GNUC__)
474475 ulong32 *S1, *S2, *S3, *S4;
520521 }
521522
522523 #ifdef LTC_CLEAN_STACK
523 int twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
524 int twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
524525 {
525526 int err = _twofish_ecb_encrypt(pt, ct, skey);
526527 burn_stack(sizeof(ulong32) * 10 + sizeof(int));
536537 @return CRYPT_OK if successful
537538 */
538539 #ifdef LTC_CLEAN_STACK
539 static int _twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
540 #else
541 int twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
542 #endif
543 {
544 ulong32 a,b,c,d,ta,tb,tc,td,t1,t2, *k;
540 static int _twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
541 #else
542 int twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
543 #endif
544 {
545 ulong32 a,b,c,d,ta,tb,tc,td,t1,t2;
546 const ulong32 *k;
545547 int r;
546548 #if !defined(LTC_TWOFISH_SMALL) && !defined(__GNUC__)
547549 ulong32 *S1, *S2, *S3, *S4;
595597 }
596598
597599 #ifdef LTC_CLEAN_STACK
598 int twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
600 int twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
599601 {
600602 int err =_twofish_ecb_decrypt(ct, pt, skey);
601603 burn_stack(sizeof(ulong32) * 10 + sizeof(int));
7070 @param skey The key as scheduled
7171 @return CRYPT_OK if successful
7272 */
73 int xtea_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
73 int xtea_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
7474 {
7575 ulong32 y, z;
7676 int r;
106106 @param skey The key as scheduled
107107 @return CRYPT_OK if successful
108108 */
109 int xtea_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
109 int xtea_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
110110 {
111111 ulong32 y, z;
112112 int r;
3737 const unsigned char *header, unsigned long headerlen,
3838 const unsigned char *ct, unsigned long ctlen,
3939 unsigned char *pt,
40 unsigned char *tag, unsigned long taglen,
40 const unsigned char *tag, unsigned long taglen,
4141 int *stat)
4242 {
4343 int err;
1818 @param gcm The GCM state which holds the H value
1919 @param I The value to multiply H by
2020 */
21 void gcm_mult_h(gcm_state *gcm, unsigned char *I)
21 void gcm_mult_h(const gcm_state *gcm, unsigned char *I)
2222 {
2323 unsigned char T[16];
2424 #ifdef LTC_GCM_TABLES
126126 T0 <= encrypt T0
127127 state <= state xor T0 xor T1
128128 */
129 static int chc_compress(hash_state *md, unsigned char *buf)
129 static int chc_compress(hash_state *md, const unsigned char *buf)
130130 {
131131 unsigned char T[2][MAXBLOCKSIZE];
132132 symmetric_key *key;
7272 #ifdef LTC_CLEAN_STACK
7373 static int _md4_compress(hash_state *md, unsigned char *buf)
7474 #else
75 static int md4_compress(hash_state *md, unsigned char *buf)
75 static int md4_compress(hash_state *md, const unsigned char *buf)
7676 #endif
7777 {
7878 ulong32 x[16], a, b, c, d;
9797 #ifdef LTC_CLEAN_STACK
9898 static int _md5_compress(hash_state *md, unsigned char *buf)
9999 #else
100 static int md5_compress(hash_state *md, unsigned char *buf)
100 static int md5_compress(hash_state *md, const unsigned char *buf)
101101 #endif
102102 {
103103 ulong32 i, W[16], a, b, c, d;
8080 #ifdef LTC_CLEAN_STACK
8181 static int _rmd128_compress(hash_state *md, unsigned char *buf)
8282 #else
83 static int rmd128_compress(hash_state *md, unsigned char *buf)
83 static int rmd128_compress(hash_state *md, const unsigned char *buf)
8484 #endif
8585 {
8686 ulong32 aa,bb,cc,dd,aaa,bbb,ccc,ddd,X[16];
100100 #ifdef LTC_CLEAN_STACK
101101 static int _rmd160_compress(hash_state *md, unsigned char *buf)
102102 #else
103 static int rmd160_compress(hash_state *md, unsigned char *buf)
103 static int rmd160_compress(hash_state *md, const unsigned char *buf)
104104 #endif
105105 {
106106 ulong32 aa,bb,cc,dd,ee,aaa,bbb,ccc,ddd,eee,X[16];
7474 #ifdef LTC_CLEAN_STACK
7575 static int _rmd256_compress(hash_state *md, unsigned char *buf)
7676 #else
77 static int rmd256_compress(hash_state *md, unsigned char *buf)
77 static int rmd256_compress(hash_state *md, const unsigned char *buf)
7878 #endif
7979 {
8080 ulong32 aa,bb,cc,dd,aaa,bbb,ccc,ddd,tmp,X[16];
9595 #ifdef LTC_CLEAN_STACK
9696 static int _rmd320_compress(hash_state *md, unsigned char *buf)
9797 #else
98 static int rmd320_compress(hash_state *md, unsigned char *buf)
98 static int rmd320_compress(hash_state *md, const unsigned char *buf)
9999 #endif
100100 {
101101 ulong32 aa,bb,cc,dd,ee,aaa,bbb,ccc,ddd,eee,tmp,X[16];
4141 #ifdef LTC_CLEAN_STACK
4242 static int _sha1_compress(hash_state *md, unsigned char *buf)
4343 #else
44 static int sha1_compress(hash_state *md, unsigned char *buf)
44 static int sha1_compress(hash_state *md, const unsigned char *buf)
4545 #endif
4646 {
4747 ulong32 a,b,c,d,e,W[80],i;
6565 #ifdef LTC_CLEAN_STACK
6666 static int _sha256_compress(hash_state * md, unsigned char *buf)
6767 #else
68 static int sha256_compress(hash_state * md, unsigned char *buf)
68 static int sha256_compress(hash_state * md, const unsigned char *buf)
6969 #endif
7070 {
7171 ulong32 S[8], W[64], t0, t1;
9090 #ifdef LTC_CLEAN_STACK
9191 static int _sha512_compress(hash_state * md, unsigned char *buf)
9292 #else
93 static int sha512_compress(hash_state * md, unsigned char *buf)
93 static int sha512_compress(hash_state * md, const unsigned char *buf)
9494 #endif
9595 {
9696 ulong64 S[8], W[80], t0, t1;
363363 return CRYPT_OK;
364364 }
365365
366 int sha3_shake_memory(int num, const unsigned char *in, unsigned long inlen, unsigned char *out, unsigned long *outlen)
366 int sha3_shake_memory(int num, const unsigned char *in, unsigned long inlen, unsigned char *out, const unsigned long *outlen)
367367 {
368368 hash_state md;
369369 int err;
573573 }
574574
575575 /* one complete pass */
576 static void pass(ulong64 *a, ulong64 *b, ulong64 *c, ulong64 *x, int mul)
576 static void pass(ulong64 *a, ulong64 *b, ulong64 *c, const ulong64 *x, int mul)
577577 {
578578 tiger_round(a,b,c,x[0],mul);
579579 tiger_round(b,c,a,x[1],mul);
607607 }
608608
609609 #ifdef LTC_CLEAN_STACK
610 static int _tiger_compress(hash_state *md, unsigned char *buf)
610 static int _tiger_compress(hash_state *md, const unsigned char *buf)
611611 #else
612 static int tiger_compress(hash_state *md, unsigned char *buf)
612 static int tiger_compress(hash_state *md, const unsigned char *buf)
613613 #endif
614614 {
615615 ulong64 a, b, c, x[8];
5252 SB7(GB(a, i-7, 0)))
5353
5454 #ifdef LTC_CLEAN_STACK
55 static int _whirlpool_compress(hash_state *md, unsigned char *buf)
55 static int _whirlpool_compress(hash_state *md, const unsigned char *buf)
5656 #else
57 static int whirlpool_compress(hash_state *md, unsigned char *buf)
57 static int whirlpool_compress(hash_state *md, const unsigned char *buf)
5858 #endif
5959 {
6060 ulong64 K[2][8], T[3][8];
396396 @param skey The scheduled key
397397 @return CRYPT_OK if successful
398398 */
399 int (*ecb_encrypt)(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
399 int (*ecb_encrypt)(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey);
400400 /** Decrypt a block
401401 @param ct The ciphertext
402402 @param pt [out] The plaintext
403403 @param skey The scheduled key
404404 @return CRYPT_OK if successful
405405 */
406 int (*ecb_decrypt)(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
406 int (*ecb_decrypt)(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey);
407407 /** Test the block cipher
408408 @return CRYPT_OK if successful, CRYPT_NOP if self-testing has been disabled
409409 */
597597 @return CRYPT_OK if successful
598598 */
599599 int (*accel_xts_encrypt)(const unsigned char *pt, unsigned char *ct,
600 unsigned long blocks, unsigned char *tweak, symmetric_key *skey1,
601 symmetric_key *skey2);
600 unsigned long blocks, unsigned char *tweak,
601 const symmetric_key *skey1, const symmetric_key *skey2);
602602
603603 /** Accelerated XTS decryption
604604 @param ct Ciphertext
612612 @return CRYPT_OK if successful
613613 */
614614 int (*accel_xts_decrypt)(const unsigned char *ct, unsigned char *pt,
615 unsigned long blocks, unsigned char *tweak, symmetric_key *skey1,
616 symmetric_key *skey2);
615 unsigned long blocks, unsigned char *tweak,
616 const symmetric_key *skey1, const symmetric_key *skey2);
617617 } cipher_descriptor[];
618618
619619 #ifdef LTC_BLOWFISH
620620 int blowfish_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
621 int blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
622 int blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
621 int blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey);
622 int blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey);
623623 int blowfish_test(void);
624624 void blowfish_done(symmetric_key *skey);
625625 int blowfish_keysize(int *keysize);
628628
629629 #ifdef LTC_RC5
630630 int rc5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
631 int rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
632 int rc5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
631 int rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey);
632 int rc5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey);
633633 int rc5_test(void);
634634 void rc5_done(symmetric_key *skey);
635635 int rc5_keysize(int *keysize);
638638
639639 #ifdef LTC_RC6
640640 int rc6_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
641 int rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
642 int rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
641 int rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey);
642 int rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey);
643643 int rc6_test(void);
644644 void rc6_done(symmetric_key *skey);
645645 int rc6_keysize(int *keysize);
649649 #ifdef LTC_RC2
650650 int rc2_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
651651 int rc2_setup_ex(const unsigned char *key, int keylen, int bits, int num_rounds, symmetric_key *skey);
652 int rc2_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
653 int rc2_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
652 int rc2_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey);
653 int rc2_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey);
654654 int rc2_test(void);
655655 void rc2_done(symmetric_key *skey);
656656 int rc2_keysize(int *keysize);
659659
660660 #ifdef LTC_SAFERP
661661 int saferp_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
662 int saferp_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
663 int saferp_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
662 int saferp_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey);
663 int saferp_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey);
664664 int saferp_test(void);
665665 void saferp_done(symmetric_key *skey);
666666 int saferp_keysize(int *keysize);
672672 int safer_sk64_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
673673 int safer_k128_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
674674 int safer_sk128_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
675 int safer_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key);
676 int safer_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key);
675 int safer_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *key);
676 int safer_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *key);
677677 int safer_k64_test(void);
678678 int safer_sk64_test(void);
679679 int safer_sk128_test(void);
698698 #define aes_enc_keysize rijndael_enc_keysize
699699
700700 int rijndael_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
701 int rijndael_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
702 int rijndael_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
701 int rijndael_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey);
702 int rijndael_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey);
703703 int rijndael_test(void);
704704 void rijndael_done(symmetric_key *skey);
705705 int rijndael_keysize(int *keysize);
706706 int rijndael_enc_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
707 int rijndael_enc_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
707 int rijndael_enc_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey);
708708 void rijndael_enc_done(symmetric_key *skey);
709709 int rijndael_enc_keysize(int *keysize);
710710 extern const struct ltc_cipher_descriptor rijndael_desc, aes_desc;
713713
714714 #ifdef LTC_XTEA
715715 int xtea_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
716 int xtea_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
717 int xtea_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
716 int xtea_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey);
717 int xtea_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey);
718718 int xtea_test(void);
719719 void xtea_done(symmetric_key *skey);
720720 int xtea_keysize(int *keysize);
723723
724724 #ifdef LTC_TWOFISH
725725 int twofish_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
726 int twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
727 int twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
726 int twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey);
727 int twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey);
728728 int twofish_test(void);
729729 void twofish_done(symmetric_key *skey);
730730 int twofish_keysize(int *keysize);
733733
734734 #ifdef LTC_DES
735735 int des_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
736 int des_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
737 int des_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
736 int des_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey);
737 int des_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey);
738738 int des_test(void);
739739 void des_done(symmetric_key *skey);
740740 int des_keysize(int *keysize);
741741 int des3_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
742 int des3_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
743 int des3_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
742 int des3_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey);
743 int des3_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey);
744744 int des3_test(void);
745745 void des3_done(symmetric_key *skey);
746746 int des3_keysize(int *keysize);
749749
750750 #ifdef LTC_CAST5
751751 int cast5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
752 int cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
753 int cast5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
752 int cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey);
753 int cast5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey);
754754 int cast5_test(void);
755755 void cast5_done(symmetric_key *skey);
756756 int cast5_keysize(int *keysize);
759759
760760 #ifdef LTC_NOEKEON
761761 int noekeon_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
762 int noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
763 int noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
762 int noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey);
763 int noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey);
764764 int noekeon_test(void);
765765 void noekeon_done(symmetric_key *skey);
766766 int noekeon_keysize(int *keysize);
769769
770770 #ifdef LTC_SKIPJACK
771771 int skipjack_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
772 int skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
773 int skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
772 int skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey);
773 int skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey);
774774 int skipjack_test(void);
775775 void skipjack_done(symmetric_key *skey);
776776 int skipjack_keysize(int *keysize);
779779
780780 #ifdef LTC_KHAZAD
781781 int khazad_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
782 int khazad_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
783 int khazad_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
782 int khazad_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey);
783 int khazad_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey);
784784 int khazad_test(void);
785785 void khazad_done(symmetric_key *skey);
786786 int khazad_keysize(int *keysize);
789789
790790 #ifdef LTC_ANUBIS
791791 int anubis_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
792 int anubis_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
793 int anubis_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
792 int anubis_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey);
793 int anubis_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey);
794794 int anubis_test(void);
795795 void anubis_done(symmetric_key *skey);
796796 int anubis_keysize(int *keysize);
799799
800800 #ifdef LTC_KSEED
801801 int kseed_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
802 int kseed_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
803 int kseed_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
802 int kseed_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey);
803 int kseed_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey);
804804 int kseed_test(void);
805805 void kseed_done(symmetric_key *skey);
806806 int kseed_keysize(int *keysize);
809809
810810 #ifdef LTC_KASUMI
811811 int kasumi_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
812 int kasumi_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
813 int kasumi_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
812 int kasumi_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey);
813 int kasumi_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey);
814814 int kasumi_test(void);
815815 void kasumi_done(symmetric_key *skey);
816816 int kasumi_keysize(int *keysize);
820820
821821 #ifdef LTC_MULTI2
822822 int multi2_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
823 int multi2_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
824 int multi2_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
823 int multi2_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey);
824 int multi2_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey);
825825 int multi2_test(void);
826826 void multi2_done(symmetric_key *skey);
827827 int multi2_keysize(int *keysize);
830830
831831 #ifdef LTC_CAMELLIA
832832 int camellia_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
833 int camellia_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
834 int camellia_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
833 int camellia_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey);
834 int camellia_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey);
835835 int camellia_test(void);
836836 void camellia_done(symmetric_key *skey);
837837 int camellia_keysize(int *keysize);
840840
841841 #ifdef LTC_IDEA
842842 int idea_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
843 int idea_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
844 int idea_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
843 int idea_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey);
844 int idea_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey);
845845 int idea_test(void);
846846 void idea_done(symmetric_key *skey);
847847 int idea_keysize(int *keysize);
850850
851851 #ifdef LTC_SERPENT
852852 int serpent_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
853 int serpent_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
854 int serpent_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
853 int serpent_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey);
854 int serpent_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey);
855855 int serpent_test(void);
856856 void serpent_done(symmetric_key *skey);
857857 int serpent_keysize(int *keysize);
871871 int keylen, int num_rounds, symmetric_CFB *cfb);
872872 int cfb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_CFB *cfb);
873873 int cfb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_CFB *cfb);
874 int cfb_getiv(unsigned char *IV, unsigned long *len, symmetric_CFB *cfb);
874 int cfb_getiv(unsigned char *IV, unsigned long *len, const symmetric_CFB *cfb);
875875 int cfb_setiv(const unsigned char *IV, unsigned long len, symmetric_CFB *cfb);
876876 int cfb_done(symmetric_CFB *cfb);
877877 #endif
881881 int keylen, int num_rounds, symmetric_OFB *ofb);
882882 int ofb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_OFB *ofb);
883883 int ofb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_OFB *ofb);
884 int ofb_getiv(unsigned char *IV, unsigned long *len, symmetric_OFB *ofb);
884 int ofb_getiv(unsigned char *IV, unsigned long *len, const symmetric_OFB *ofb);
885885 int ofb_setiv(const unsigned char *IV, unsigned long len, symmetric_OFB *ofb);
886886 int ofb_done(symmetric_OFB *ofb);
887887 #endif
891891 int keylen, int num_rounds, symmetric_CBC *cbc);
892892 int cbc_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_CBC *cbc);
893893 int cbc_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_CBC *cbc);
894 int cbc_getiv(unsigned char *IV, unsigned long *len, symmetric_CBC *cbc);
894 int cbc_getiv(unsigned char *IV, unsigned long *len, const symmetric_CBC *cbc);
895895 int cbc_setiv(const unsigned char *IV, unsigned long len, symmetric_CBC *cbc);
896896 int cbc_done(symmetric_CBC *cbc);
897897 #endif
909909 symmetric_CTR *ctr);
910910 int ctr_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_CTR *ctr);
911911 int ctr_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_CTR *ctr);
912 int ctr_getiv(unsigned char *IV, unsigned long *len, symmetric_CTR *ctr);
912 int ctr_getiv(unsigned char *IV, unsigned long *len, const symmetric_CTR *ctr);
913913 int ctr_setiv(const unsigned char *IV, unsigned long len, symmetric_CTR *ctr);
914914 int ctr_done(symmetric_CTR *ctr);
915915 int ctr_test(void);
928928 symmetric_LRW *lrw);
929929 int lrw_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_LRW *lrw);
930930 int lrw_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_LRW *lrw);
931 int lrw_getiv(unsigned char *IV, unsigned long *len, symmetric_LRW *lrw);
931 int lrw_getiv(unsigned char *IV, unsigned long *len, const symmetric_LRW *lrw);
932932 int lrw_setiv(const unsigned char *IV, unsigned long len, symmetric_LRW *lrw);
933933 int lrw_done(symmetric_LRW *lrw);
934934 int lrw_test(void);
944944 int num_rounds, symmetric_F8 *f8);
945945 int f8_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_F8 *f8);
946946 int f8_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_F8 *f8);
947 int f8_getiv(unsigned char *IV, unsigned long *len, symmetric_F8 *f8);
947 int f8_getiv(unsigned char *IV, unsigned long *len, const symmetric_F8 *f8);
948948 int f8_setiv(const unsigned char *IV, unsigned long len, symmetric_F8 *f8);
949949 int f8_done(symmetric_F8 *f8);
950950 int f8_test_mode(void);
967967 const unsigned char *pt, unsigned long ptlen,
968968 unsigned char *ct,
969969 unsigned char *tweak,
970 symmetric_xts *xts);
970 const symmetric_xts *xts);
971971 int xts_decrypt(
972972 const unsigned char *ct, unsigned long ptlen,
973973 unsigned char *pt,
974974 unsigned char *tweak,
975 symmetric_xts *xts);
975 const symmetric_xts *xts);
976976
977977 void xts_done(symmetric_xts *xts);
978978 int xts_test(void);
10451045 unsigned ptr;
10461046 } sosemanuk_state;
10471047
1048 int sosemanuk_setup(sosemanuk_state *ss, unsigned char *key, unsigned long keylen);
1049 int sosemanuk_setiv(sosemanuk_state *ss, unsigned char *iv, unsigned long ivlen);
1048 int sosemanuk_setup(sosemanuk_state *ss, const unsigned char *key, unsigned long keylen);
1049 int sosemanuk_setiv(sosemanuk_state *ss, const unsigned char *iv, unsigned long ivlen);
10501050 int sosemanuk_crypt(sosemanuk_state *ss, const unsigned char *in, unsigned long datalen, unsigned char *out);
10511051 int sosemanuk_keystream(sosemanuk_state *ss, unsigned char *out, unsigned long outlen);
10521052 int sosemanuk_done(sosemanuk_state *ss);
357357
358358 #ifdef LTC_FORTUNA
359359
360 #if !defined(LTC_FORTUNA_RESEED_RATELIMIT_STATIC) && \
361 ((defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L) || defined(_WIN32))
362
363 /* time-based rate limit of the reseeding */
364 #define LTC_FORTUNA_RESEED_RATELIMIT_TIMED
365
366 #else
367
360368 #ifndef LTC_FORTUNA_WD
361369 /* reseed every N calls to the read function */
362370 #define LTC_FORTUNA_WD 10
371 #endif
372
373 #ifdef LTC_FORTUNA_RESEED_RATELIMIT_TIMED
374 /* make sure only one of
375 * LTC_FORTUNA_RESEED_RATELIMIT_STATIC
376 * and
377 * LTC_FORTUNA_RESEED_RATELIMIT_TIMED
378 * is defined.
379 */
380 #undef LTC_FORTUNA_RESEED_RATELIMIT_TIMED
381 #warning "undef'ed LTC_FORTUNA_RESEED_RATELIMIT_TIMED, looks like your architecture doesn't support it"
382 #endif
383
363384 #endif
364385
365386 #ifndef LTC_FORTUNA_POOLS
287287 #define sha3_shake_process(a,b,c) sha3_process(a,b,c)
288288 int sha3_shake_done(hash_state *md, unsigned char *out, unsigned long outlen);
289289 int sha3_shake_test(void);
290 int sha3_shake_memory(int num, const unsigned char *in, unsigned long inlen, unsigned char *out, unsigned long *outlen);
290 int sha3_shake_memory(int num, const unsigned char *in, unsigned long inlen, unsigned char *out, const unsigned long *outlen);
291291 #endif
292292
293293 #ifdef LTC_KECCAK
273273 const unsigned char *header, unsigned long headerlen,
274274 const unsigned char *ct, unsigned long ctlen,
275275 unsigned char *pt,
276 unsigned char *tag, unsigned long taglen,
276 const unsigned char *tag, unsigned long taglen,
277277 int *stat);
278278
279279 int eax_test(void);
499499 #endif
500500 } gcm_state;
501501
502 void gcm_mult_h(gcm_state *gcm, unsigned char *I);
502 void gcm_mult_h(const gcm_state *gcm, unsigned char *I);
503503
504504 int gcm_init(gcm_state *gcm, int cipher,
505505 const unsigned char *key, int keylen);
473473 */
474474 int (*rsa_me)(const unsigned char *in, unsigned long inlen,
475475 unsigned char *out, unsigned long *outlen, int which,
476 rsa_key *key);
476 const rsa_key *key);
477477
478478 /* ---- basic math continued ---- */
479479
122122
123123 void adler32_init(adler32_state *ctx);
124124 void adler32_update(adler32_state *ctx, const unsigned char *input, unsigned long length);
125 void adler32_finish(adler32_state *ctx, void *hash, unsigned long size);
125 void adler32_finish(const adler32_state *ctx, void *hash, unsigned long size);
126126 int adler32_test(void);
127127 #endif
128128
134134
135135 void crc32_init(crc32_state *ctx);
136136 void crc32_update(crc32_state *ctx, const unsigned char *input, unsigned long length);
137 void crc32_finish(crc32_state *ctx, void *hash, unsigned long size);
137 void crc32_finish(const crc32_state *ctx, void *hash, unsigned long size);
138138 int crc32_test(void);
139139 #endif
140140
153153 };
154154
155155 int padding_pad(unsigned char *data, unsigned long length, unsigned long* padded_length, unsigned long mode);
156 int padding_depad(unsigned char *data, unsigned long *length, unsigned long mode);
156 int padding_depad(const unsigned char *data, unsigned long *length, unsigned long mode);
157157
158158 #ifdef LTC_SOURCE
159159 /* internal helper functions */
4444
4545 int pk_get_oid(int pk, oid_st *st);
4646 int pk_oid_str_to_num(const char *OID, unsigned long *oid, unsigned long *oidlen);
47 int pk_oid_num_to_str(unsigned long *oid, unsigned long oidlen, char *OID, unsigned long *outlen);
47 int pk_oid_num_to_str(const unsigned long *oid, unsigned long oidlen, char *OID, unsigned long *outlen);
4848 #endif /* LTC_SOURCE */
4949
5050 /* ---- RSA ---- */
7474
7575 int rsa_make_key(prng_state *prng, int wprng, int size, long e, rsa_key *key);
7676
77 int rsa_get_size(rsa_key *key);
77 int rsa_get_size(const rsa_key *key);
7878
7979 int rsa_exptmod(const unsigned char *in, unsigned long inlen,
8080 unsigned char *out, unsigned long *outlen, int which,
81 rsa_key *key);
81 const rsa_key *key);
8282
8383 void rsa_free(rsa_key *key);
8484
9999 rsa_sign_saltlen_get_max_ex(LTC_PKCS_1_PSS, _hash_idx, _key)
100100
101101 /* These can be switched between PKCS #1 v2.x and PKCS #1 v1.5 paddings */
102 int rsa_encrypt_key_ex(const unsigned char *in, unsigned long inlen,
103 unsigned char *out, unsigned long *outlen,
104 const unsigned char *lparam, unsigned long lparamlen,
105 prng_state *prng, int prng_idx, int hash_idx, int padding, rsa_key *key);
106
107 int rsa_decrypt_key_ex(const unsigned char *in, unsigned long inlen,
102 int rsa_encrypt_key_ex(const unsigned char *in, unsigned long inlen,
108103 unsigned char *out, unsigned long *outlen,
109104 const unsigned char *lparam, unsigned long lparamlen,
105 prng_state *prng, int prng_idx,
110106 int hash_idx, int padding,
111 int *stat, rsa_key *key);
107 const rsa_key *key);
108
109 int rsa_decrypt_key_ex(const unsigned char *in, unsigned long inlen,
110 unsigned char *out, unsigned long *outlen,
111 const unsigned char *lparam, unsigned long lparamlen,
112 int hash_idx, int padding,
113 int *stat, const rsa_key *key);
112114
113115 int rsa_sign_hash_ex(const unsigned char *in, unsigned long inlen,
114116 unsigned char *out, unsigned long *outlen,
115117 int padding,
116118 prng_state *prng, int prng_idx,
117119 int hash_idx, unsigned long saltlen,
118 rsa_key *key);
119
120 int rsa_verify_hash_ex(const unsigned char *sig, unsigned long siglen,
121 const unsigned char *hash, unsigned long hashlen,
120 const rsa_key *key);
121
122 int rsa_verify_hash_ex(const unsigned char *sig, unsigned long siglen,
123 const unsigned char *hash, unsigned long hashlen,
122124 int padding,
123 int hash_idx, unsigned long saltlen,
124 int *stat, rsa_key *key);
125
126 int rsa_sign_saltlen_get_max_ex(int padding, int hash_idx, rsa_key *key);
125 int hash_idx, unsigned long saltlen,
126 int *stat, const rsa_key *key);
127
128 int rsa_sign_saltlen_get_max_ex(int padding, int hash_idx, const rsa_key *key);
127129
128130 /* PKCS #1 import/export */
129 int rsa_export(unsigned char *out, unsigned long *outlen, int type, rsa_key *key);
131 int rsa_export(unsigned char *out, unsigned long *outlen, int type, const rsa_key *key);
130132 int rsa_import(const unsigned char *in, unsigned long inlen, rsa_key *key);
131133
132134 int rsa_import_x509(const unsigned char *in, unsigned long inlen, rsa_key *key);
212214 void *prime;
213215 } dh_key;
214216
215 int dh_get_groupsize(dh_key *key);
216
217 int dh_export(unsigned char *out, unsigned long *outlen, int type, dh_key *key);
217 int dh_get_groupsize(const dh_key *key);
218
219 int dh_export(unsigned char *out, unsigned long *outlen, int type, const dh_key *key);
218220 int dh_import(const unsigned char *in, unsigned long inlen, dh_key *key);
219221
220222 int dh_set_pg(const unsigned char *p, unsigned long plen,
226228 int dh_set_key(const unsigned char *in, unsigned long inlen, int type, dh_key *key);
227229 int dh_generate_key(prng_state *prng, int wprng, dh_key *key);
228230
229 int dh_shared_secret(dh_key *private_key, dh_key *public_key,
231 int dh_shared_secret(const dh_key *private_key, const dh_key *public_key,
230232 unsigned char *out, unsigned long *outlen);
231233
232234 void dh_free(dh_key *key);
233235
234 int dh_export_key(void *out, unsigned long *outlen, int type, dh_key *key);
236 int dh_export_key(void *out, unsigned long *outlen, int type, const dh_key *key);
235237
236238 #ifdef LTC_SOURCE
237239 typedef struct {
242244 extern const ltc_dh_set_type ltc_dh_sets[];
243245
244246 /* internal helper functions */
245 int dh_check_pubkey(dh_key *key);
247 int dh_check_pubkey(const dh_key *key);
246248 #endif
247249
248250 #endif /* LTC_MDH */
510512
511513 int dsa_sign_hash_raw(const unsigned char *in, unsigned long inlen,
512514 void *r, void *s,
513 prng_state *prng, int wprng, dsa_key *key);
515 prng_state *prng, int wprng, const dsa_key *key);
514516
515517 int dsa_sign_hash(const unsigned char *in, unsigned long inlen,
516518 unsigned char *out, unsigned long *outlen,
517 prng_state *prng, int wprng, dsa_key *key);
519 prng_state *prng, int wprng, const dsa_key *key);
518520
519521 int dsa_verify_hash_raw( void *r, void *s,
520522 const unsigned char *hash, unsigned long hashlen,
521 int *stat, dsa_key *key);
522
523 int dsa_verify_hash(const unsigned char *sig, unsigned long siglen,
524 const unsigned char *hash, unsigned long hashlen,
525 int *stat, dsa_key *key);
523 int *stat, const dsa_key *key);
524
525 int dsa_verify_hash(const unsigned char *sig, unsigned long siglen,
526 const unsigned char *hash, unsigned long hashlen,
527 int *stat, const dsa_key *key);
526528
527529 int dsa_encrypt_key(const unsigned char *in, unsigned long inlen,
528530 unsigned char *out, unsigned long *outlen,
529 prng_state *prng, int wprng, int hash,
530 dsa_key *key);
531 prng_state *prng, int wprng, int hash,
532 const dsa_key *key);
531533
532534 int dsa_decrypt_key(const unsigned char *in, unsigned long inlen,
533535 unsigned char *out, unsigned long *outlen,
534 dsa_key *key);
536 const dsa_key *key);
535537
536538 int dsa_import(const unsigned char *in, unsigned long inlen, dsa_key *key);
537 int dsa_export(unsigned char *out, unsigned long *outlen, int type, dsa_key *key);
538 int dsa_verify_key(dsa_key *key, int *stat);
539 int dsa_export(unsigned char *out, unsigned long *outlen, int type, const dsa_key *key);
540 int dsa_verify_key(const dsa_key *key, int *stat);
539541 #ifdef LTC_SOURCE
540542 /* internal helper functions */
541 int dsa_int_validate_xy(dsa_key *key, int *stat);
542 int dsa_int_validate_pqg(dsa_key *key, int *stat);
543 int dsa_int_validate_primes(dsa_key *key, int *stat);
543 int dsa_int_validate_xy(const dsa_key *key, int *stat);
544 int dsa_int_validate_pqg(const dsa_key *key, int *stat);
545 int dsa_int_validate_primes(const dsa_key *key, int *stat);
544546 #endif
545547 int dsa_shared_secret(void *private_key, void *base,
546 dsa_key *public_key,
548 const dsa_key *public_key,
547549 unsigned char *out, unsigned long *outlen);
548550 #endif
549551
661663 extern const unsigned long der_asn1_tag_to_string_map_sz;
662664
663665 /* SEQUENCE */
664 int der_encode_sequence_ex(ltc_asn1_list *list, unsigned long inlen,
665 unsigned char *out, unsigned long *outlen, int type_of);
666 int der_encode_sequence_ex(const ltc_asn1_list *list, unsigned long inlen,
667 unsigned char *out, unsigned long *outlen, int type_of);
666668
667669 #define der_encode_sequence(list, inlen, out, outlen) der_encode_sequence_ex(list, inlen, out, outlen, LTC_ASN1_SEQUENCE)
668670
693695 #define der_decode_sequence(in, inlen, list, outlen) der_decode_sequence_ex(in, inlen, list, outlen, LTC_DER_SEQ_SEQUENCE | LTC_DER_SEQ_RELAXED)
694696 #define der_decode_sequence_strict(in, inlen, list, outlen) der_decode_sequence_ex(in, inlen, list, outlen, LTC_DER_SEQ_SEQUENCE | LTC_DER_SEQ_STRICT)
695697
696 int der_length_sequence(ltc_asn1_list *list, unsigned long inlen,
698 int der_length_sequence(const ltc_asn1_list *list, unsigned long inlen,
697699 unsigned long *outlen);
698700
699701
722724 int der_decode_asn1_length(const unsigned char* len, unsigned long* lenlen, unsigned long* outlen);
723725 int der_length_asn1_length(unsigned long len, unsigned long *outlen);
724726
725 int der_length_sequence_ex(ltc_asn1_list *list, unsigned long inlen,
727 int der_length_sequence_ex(const ltc_asn1_list *list, unsigned long inlen,
726728 unsigned long *outlen, unsigned long *payloadlen);
727729
728730 extern const ltc_asn1_type der_asn1_tag_to_type_map[];
735737 /* SET */
736738 #define der_decode_set(in, inlen, list, outlen) der_decode_sequence_ex(in, inlen, list, outlen, LTC_DER_SEQ_SET)
737739 #define der_length_set der_length_sequence
738 int der_encode_set(ltc_asn1_list *list, unsigned long inlen,
739 unsigned char *out, unsigned long *outlen);
740
741 int der_encode_setof(ltc_asn1_list *list, unsigned long inlen,
742 unsigned char *out, unsigned long *outlen);
740 int der_encode_set(const ltc_asn1_list *list, unsigned long inlen,
741 unsigned char *out, unsigned long *outlen);
742
743 int der_encode_setof(const ltc_asn1_list *list, unsigned long inlen,
744 unsigned char *out, unsigned long *outlen);
743745
744746 /* VA list handy helpers with triplets of <type, size, data> */
745747 int der_encode_sequence_multi(unsigned char *out, unsigned long *outlen, ...);
790792 int der_length_octet_string(unsigned long noctets, unsigned long *outlen);
791793
792794 /* OBJECT IDENTIFIER */
793 int der_encode_object_identifier(unsigned long *words, unsigned long nwords,
794 unsigned char *out, unsigned long *outlen);
795 int der_encode_object_identifier(const unsigned long *words, unsigned long nwords,
796 unsigned char *out, unsigned long *outlen);
795797 int der_decode_object_identifier(const unsigned char *in, unsigned long inlen,
796798 unsigned long *words, unsigned long *outlen);
797 int der_length_object_identifier(unsigned long *words, unsigned long nwords, unsigned long *outlen);
799 int der_length_object_identifier(const unsigned long *words, unsigned long nwords, unsigned long *outlen);
798800 unsigned long der_object_identifier_bits(unsigned long x);
799801
800802 /* IA5 STRING */
873875 off_mm; /* timezone offset minutes */
874876 } ltc_utctime;
875877
876 int der_encode_utctime(ltc_utctime *utctime,
877 unsigned char *out, unsigned long *outlen);
878 int der_encode_utctime(const ltc_utctime *utctime,
879 unsigned char *out, unsigned long *outlen);
878880
879881 int der_decode_utctime(const unsigned char *in, unsigned long *inlen,
880882 ltc_utctime *out);
881883
882 int der_length_utctime(ltc_utctime *utctime, unsigned long *outlen);
884 int der_length_utctime(const ltc_utctime *utctime, unsigned long *outlen);
883885
884886 /* GeneralizedTime */
885887 typedef struct {
895897 off_mm; /* timezone offset minutes */
896898 } ltc_generalizedtime;
897899
898 int der_encode_generalizedtime(ltc_generalizedtime *gtime,
899 unsigned char *out, unsigned long *outlen);
900 int der_encode_generalizedtime(const ltc_generalizedtime *gtime,
901 unsigned char *out, unsigned long *outlen);
900902
901903 int der_decode_generalizedtime(const unsigned char *in, unsigned long *inlen,
902904 ltc_generalizedtime *out);
903905
904 int der_length_generalizedtime(ltc_generalizedtime *gtime, unsigned long *outlen);
906 int der_length_generalizedtime(const ltc_generalizedtime *gtime, unsigned long *outlen);
905907
906908 #ifdef LTC_SOURCE
907909 /* internal helper functions */
4242 pool0_len, /* length of 0'th pool */
4343 wd;
4444
45 ulong64 reset_cnt; /* number of times we have reset */
45 ulong64 reset_cnt; /* number of times we have reseeded */
4646 };
4747 #endif
4848
147147 #ifdef LTC_FORTUNA
148148 int fortuna_start(prng_state *prng);
149149 int fortuna_add_entropy(const unsigned char *in, unsigned long inlen, prng_state *prng);
150 int fortuna_add_random_event(unsigned long source, unsigned long pool, const unsigned char *in, unsigned long inlen, prng_state *prng);
150151 int fortuna_ready(prng_state *prng);
151152 unsigned long fortuna_read(unsigned char *out, unsigned long outlen, prng_state *prng);
152153 int fortuna_done(prng_state *prng);
153 int fortuna_export(unsigned char *out, unsigned long *outlen, prng_state *prng);
154 int fortuna_import(const unsigned char *in, unsigned long inlen, prng_state *prng);
155 int fortuna_test(void);
154 int fortuna_export(unsigned char *out, unsigned long *outlen, prng_state *prng);
155 int fortuna_import(const unsigned char *in, unsigned long inlen, prng_state *prng);
156 int fortuna_update_seed(const unsigned char *in, unsigned long inlen, prng_state *prng);
157 int fortuna_test(void);
156158 extern const struct ltc_prng_descriptor fortuna_desc;
157159 #endif
158160
6666 cur = va_arg(args, void**);
6767 }
6868 va_end(args);
69 return;
7069 }
7170
7271 #endif
7878 ctx->s[1] = (unsigned short)s2;
7979 }
8080
81 void adler32_finish(adler32_state *ctx, void *hash, unsigned long size)
81 void adler32_finish(const adler32_state *ctx, void *hash, unsigned long size)
8282 {
8383 unsigned char* h;
8484
2424 unsigned long y;
2525 #ifdef LTC_FAST
2626 unsigned long z;
27 LTC_FAST_TYPE fastMask = ~0; /* initialize fastMask at all ones */
27 LTC_FAST_TYPE fastMask = ~(LTC_FAST_TYPE)0; /* initialize fastMask at all ones */
2828 #endif
2929 unsigned char mask = 0xff; /* initialize mask at all ones */
3030
158158 ctx->crc = crc;
159159 }
160160
161 void crc32_finish(crc32_state *ctx, void *hash, unsigned long size)
161 void crc32_finish(const crc32_state *ctx, void *hash, unsigned long size)
162162 {
163163 unsigned long i;
164164 unsigned char* h;
312312 " ChaCha20\n"
313313 #endif
314314 #if defined(LTC_FORTUNA)
315 " Fortuna (" NAME_VALUE(LTC_FORTUNA_POOLS) ", " NAME_VALUE(LTC_FORTUNA_WD) ")\n"
315 " Fortuna (" NAME_VALUE(LTC_FORTUNA_POOLS) ", "
316 #if defined(LTC_FORTUNA_RESEED_RATELIMIT_TIMED)
317 "LTC_FORTUNA_RESEED_RATELIMIT_TIMED, "
318 #else
319 "LTC_FORTUNA_RESEED_RATELIMIT_STATIC, " NAME_VALUE(LTC_FORTUNA_WD)
320 #endif
321 ")\n"
316322 #endif
317323 #if defined(LTC_SOBER128)
318324 " SOBER128\n"
1919 @param mode One of the LTC_PAD_xx flags
2020 @return CRYPT_OK on success
2121 */
22 int padding_depad(unsigned char *data, unsigned long *length, unsigned long mode)
22 int padding_depad(const unsigned char *data, unsigned long *length, unsigned long mode)
2323 {
2424 unsigned long padded_length, unpadded_length, n;
2525 unsigned char pad;
3737 return CRYPT_OK;
3838 }
3939
40 int pk_oid_num_to_str(unsigned long *oid, unsigned long oidlen, char *OID, unsigned long *outlen)
40 int pk_oid_num_to_str(const unsigned long *oid, unsigned long oidlen, char *OID, unsigned long *outlen)
4141 {
4242 int i;
4343 unsigned long j, k;
2121 @param cbc The CBC state
2222 @return CRYPT_OK if successful
2323 */
24 int cbc_getiv(unsigned char *IV, unsigned long *len, symmetric_CBC *cbc)
24 int cbc_getiv(unsigned char *IV, unsigned long *len, const symmetric_CBC *cbc)
2525 {
2626 LTC_ARGCHK(IV != NULL);
2727 LTC_ARGCHK(len != NULL);
2121 @param cfb The CFB state
2222 @return CRYPT_OK if successful
2323 */
24 int cfb_getiv(unsigned char *IV, unsigned long *len, symmetric_CFB *cfb)
24 int cfb_getiv(unsigned char *IV, unsigned long *len, const symmetric_CFB *cfb)
2525 {
2626 LTC_ARGCHK(IV != NULL);
2727 LTC_ARGCHK(len != NULL);
2121 @param ctr The CTR state
2222 @return CRYPT_OK if successful
2323 */
24 int ctr_getiv(unsigned char *IV, unsigned long *len, symmetric_CTR *ctr)
24 int ctr_getiv(unsigned char *IV, unsigned long *len, const symmetric_CTR *ctr)
2525 {
2626 LTC_ARGCHK(IV != NULL);
2727 LTC_ARGCHK(len != NULL);
2121 @param ofb The OFB state
2222 @return CRYPT_OK if successful
2323 */
24 int ofb_getiv(unsigned char *IV, unsigned long *len, symmetric_OFB *ofb)
24 int ofb_getiv(unsigned char *IV, unsigned long *len, const symmetric_OFB *ofb)
2525 {
2626 LTC_ARGCHK(IV != NULL);
2727 LTC_ARGCHK(len != NULL);
3636 @param outlen [in/out] The length of the DER encoding
3737 @return CRYPT_OK if successful
3838 */
39 int der_encode_generalizedtime(ltc_generalizedtime *gtime,
40 unsigned char *out, unsigned long *outlen)
39 int der_encode_generalizedtime(const ltc_generalizedtime *gtime,
40 unsigned char *out, unsigned long *outlen)
4141 {
4242 unsigned long x, tmplen;
4343 int err;
2121 @param outlen [out] The length of the DER encoding
2222 @return CRYPT_OK if successful
2323 */
24 int der_length_generalizedtime(ltc_generalizedtime *gtime, unsigned long *outlen)
24 int der_length_generalizedtime(const ltc_generalizedtime *gtime, unsigned long *outlen)
2525 {
2626 LTC_ARGCHK(outlen != NULL);
2727 LTC_ARGCHK(gtime != NULL);
2121 @param outlen [in/out] The max and resulting size of the OID
2222 @return CRYPT_OK if successful
2323 */
24 int der_encode_object_identifier(unsigned long *words, unsigned long nwords,
25 unsigned char *out, unsigned long *outlen)
24 int der_encode_object_identifier(const unsigned long *words, unsigned long nwords,
25 unsigned char *out, unsigned long *outlen)
2626 {
2727 unsigned long i, x, y, z, t, mask, wordbuf;
2828 int err;
3434 @param outlen [out] The length of the DER encoding for the given string
3535 @return CRYPT_OK if successful
3636 */
37 int der_length_object_identifier(unsigned long *words, unsigned long nwords, unsigned long *outlen)
37 int der_length_object_identifier(const unsigned long *words, unsigned long nwords, unsigned long *outlen)
3838 {
3939 unsigned long y, z, t, wordbuf;
4040
2424 @param type_of LTC_ASN1_SEQUENCE or LTC_ASN1_SET/LTC_ASN1_SETOF
2525 @return CRYPT_OK on success
2626 */
27 int der_encode_sequence_ex(ltc_asn1_list *list, unsigned long inlen,
28 unsigned char *out, unsigned long *outlen, int type_of)
27 int der_encode_sequence_ex(const ltc_asn1_list *list, unsigned long inlen,
28 unsigned char *out, unsigned long *outlen, int type_of)
2929 {
3030 int err;
3131 ltc_asn1_type type;
2121 @param outlen [out] The length required in octets to store it
2222 @return CRYPT_OK on success
2323 */
24 int der_length_sequence(ltc_asn1_list *list, unsigned long inlen,
24 int der_length_sequence(const ltc_asn1_list *list, unsigned long inlen,
2525 unsigned long *outlen)
2626 {
2727 return der_length_sequence_ex(list, inlen, outlen, NULL);
2828 }
2929
30 int der_length_sequence_ex(ltc_asn1_list *list, unsigned long inlen,
30 int der_length_sequence_ex(const ltc_asn1_list *list, unsigned long inlen,
3131 unsigned long *outlen, unsigned long *payloadlen)
3232 {
3333 int err;
4545 @param outlen [in/out] The size of the output
4646 @return CRYPT_OK on success
4747 */
48 int der_encode_set(ltc_asn1_list *list, unsigned long inlen,
49 unsigned char *out, unsigned long *outlen)
48 int der_encode_set(const ltc_asn1_list *list, unsigned long inlen,
49 unsigned char *out, unsigned long *outlen)
5050 {
5151 ltc_asn1_list *copy;
5252 unsigned long x;
5555 @param outlen [in/out] The size of the output
5656 @return CRYPT_OK on success
5757 */
58 int der_encode_setof(ltc_asn1_list *list, unsigned long inlen,
59 unsigned char *out, unsigned long *outlen)
58 int der_encode_setof(const ltc_asn1_list *list, unsigned long inlen,
59 unsigned char *out, unsigned long *outlen)
6060 {
6161 unsigned long x, y, z;
6262 ptrdiff_t hdrlen;
2727 @param outlen [in/out] The length of the DER encoding
2828 @return CRYPT_OK if successful
2929 */
30 int der_encode_utctime(ltc_utctime *utctime,
31 unsigned char *out, unsigned long *outlen)
30 int der_encode_utctime(const ltc_utctime *utctime,
31 unsigned char *out, unsigned long *outlen)
3232 {
3333 unsigned long x, tmplen;
3434 int err;
2020 @param outlen [out] The length of the DER encoding
2121 @return CRYPT_OK if successful
2222 */
23 int der_length_utctime(ltc_utctime *utctime, unsigned long *outlen)
23 int der_length_utctime(const ltc_utctime *utctime, unsigned long *outlen)
2424 {
2525 LTC_ARGCHK(outlen != NULL);
2626 LTC_ARGCHK(utctime != NULL);
9292 }
9393
9494 if ((alg_id[0].size != oid.OIDlen) ||
95 XMEMCMP(oid.OID, alg_id[0].data, oid.OIDlen * sizeof(oid.OID[0]))) {
95 XMEMCMP(oid.OID, alg_id[0].data, oid.OIDlen * sizeof(oid.OID[0])) != 0) {
9696 /* OID mismatch */
9797 err = CRYPT_PK_INVALID_TYPE;
9898 goto LBL_ERR;
223223 @param key The DH key to get the size of
224224 @return The group size in octets (0 on error)
225225 */
226 int dh_get_groupsize(dh_key *key)
226 int dh_get_groupsize(const dh_key *key)
227227 {
228228 if (key == NULL) return 0;
229229 return mp_unsigned_bin_size(key->prime);
1515 @param key The key you wish to test
1616 @return CRYPT_OK if successful
1717 */
18 int dh_check_pubkey(dh_key *key)
18 int dh_check_pubkey(const dh_key *key)
1919 {
2020 void *p_minus1;
2121 ltc_mp_digit digit;
1818 @param key The key you wish to export
1919 @return CRYPT_OK if successful
2020 */
21 int dh_export(unsigned char *out, unsigned long *outlen, int type, dh_key *key)
21 int dh_export(unsigned char *out, unsigned long *outlen, int type, const dh_key *key)
2222 {
2323 unsigned char flags[1];
2424 int err;
1818 @param key The key you wish to export
1919 @return CRYPT_OK if successful
2020 */
21 int dh_export_key(void *out, unsigned long *outlen, int type, dh_key *key)
21 int dh_export_key(void *out, unsigned long *outlen, int type, const dh_key *key)
2222 {
2323 unsigned long len;
2424 void *k;
1818 @param outlen [in/out] The max size and resulting size of the shared data.
1919 @return CRYPT_OK if successful
2020 */
21 int dh_shared_secret(dh_key *private_key, dh_key *public_key,
21 int dh_shared_secret(const dh_key *private_key, const dh_key *public_key,
2222 unsigned char *out, unsigned long *outlen)
2323 {
2424 void *tmp;
2525 */
2626 int dsa_decrypt_key(const unsigned char *in, unsigned long inlen,
2727 unsigned char *out, unsigned long *outlen,
28 dsa_key *key)
28 const dsa_key *key)
2929 {
3030 unsigned char *skey, *expt;
3131 void *g_pub;
2828 */
2929 int dsa_encrypt_key(const unsigned char *in, unsigned long inlen,
3030 unsigned char *out, unsigned long *outlen,
31 prng_state *prng, int wprng, int hash,
32 dsa_key *key)
31 prng_state *prng, int wprng, int hash,
32 const dsa_key *key)
3333 {
3434 unsigned char *expt, *skey;
3535 void *g_pub, *g_priv;
2222 @param key The key to export
2323 @return CRYPT_OK if successful
2424 */
25 int dsa_export(unsigned char *out, unsigned long *outlen, int type, dsa_key *key)
25 int dsa_export(unsigned char *out, unsigned long *outlen, int type, const dsa_key *key)
2626 {
2727 unsigned long zero=0;
2828 int err, std;
6868 }
6969 } else {
7070 if (std) {
71 unsigned long tmplen = (mp_count_bits(key->y) / 8) + 8;
71 unsigned long tmplen = (unsigned long)(mp_count_bits(key->y) / 8) + 8;
7272 unsigned char* tmp = XMALLOC(tmplen);
7373 ltc_asn1_list int_list[3];
7474
7171 */
7272
7373 seedbytes = group_size;
74 L = modulus_size * 8;
75 N = group_size * 8;
74 L = (unsigned long)modulus_size * 8;
75 N = (unsigned long)group_size * 8;
7676
7777 /* XXX-TODO no Lucas test */
7878 #ifdef LTC_MPI_HAS_LUCAS_TEST
2424 @return CRYPT_OK if successful
2525 */
2626 int dsa_shared_secret(void *private_key, void *base,
27 dsa_key *public_key,
27 const dsa_key *public_key,
2828 unsigned char *out, unsigned long *outlen)
2929 {
3030 unsigned long x;
2727 */
2828 int dsa_sign_hash_raw(const unsigned char *in, unsigned long inlen,
2929 void *r, void *s,
30 prng_state *prng, int wprng, dsa_key *key)
30 prng_state *prng, int wprng, const dsa_key *key)
3131 {
3232 void *k, *kinv, *tmp;
3333 unsigned char *buf;
116116 */
117117 int dsa_sign_hash(const unsigned char *in, unsigned long inlen,
118118 unsigned char *out, unsigned long *outlen,
119 prng_state *prng, int wprng, dsa_key *key)
119 prng_state *prng, int wprng, const dsa_key *key)
120120 {
121121 void *r, *s;
122122 int err;
2727 */
2828 int dsa_verify_hash_raw( void *r, void *s,
2929 const unsigned char *hash, unsigned long hashlen,
30 int *stat, dsa_key *key)
30 int *stat, const dsa_key *key)
3131 {
3232 void *w, *v, *u1, *u2;
3333 int err;
9191 @param key The corresponding public DSA key
9292 @return CRYPT_OK if successful (even if the signature is invalid)
9393 */
94 int dsa_verify_hash(const unsigned char *sig, unsigned long siglen,
95 const unsigned char *hash, unsigned long hashlen,
96 int *stat, dsa_key *key)
94 int dsa_verify_hash(const unsigned char *sig, unsigned long siglen,
95 const unsigned char *hash, unsigned long hashlen,
96 int *stat, const dsa_key *key)
9797 {
9898 int err;
9999 void *r, *s;
2525 @param stat [out] Result of test, 1==valid, 0==invalid
2626 @return CRYPT_OK if successful
2727 */
28 int dsa_verify_key(dsa_key *key, int *stat)
28 int dsa_verify_key(const dsa_key *key, int *stat)
2929 {
3030 int err;
3131
4646 @param stat [out] Result of test, 1==valid, 0==invalid
4747 @return CRYPT_OK if successful
4848 */
49 int dsa_int_validate_pqg(dsa_key *key, int *stat)
49 int dsa_int_validate_pqg(const dsa_key *key, int *stat)
5050 {
5151 void *tmp1, *tmp2;
5252 int err;
100100 @param stat [out] Result of test, 1==valid, 0==invalid
101101 @return CRYPT_OK if successful
102102 */
103 int dsa_int_validate_primes(dsa_key *key, int *stat)
103 int dsa_int_validate_primes(const dsa_key *key, int *stat)
104104 {
105105 int err, res;
106106
135135 @param stat [out] Result of test, 1==valid, 0==invalid
136136 @return CRYPT_OK if successful
137137 */
138 int dsa_int_validate_xy(dsa_key *key, int *stat)
138 int dsa_int_validate_xy(const dsa_key *key, int *stat)
139139 {
140140 void *tmp;
141141 int err;
2828 @param key The corresponding private RSA key
2929 @return CRYPT_OK if succcessul (even if invalid)
3030 */
31 int rsa_decrypt_key_ex(const unsigned char *in, unsigned long inlen,
32 unsigned char *out, unsigned long *outlen,
33 const unsigned char *lparam, unsigned long lparamlen,
34 int hash_idx, int padding,
35 int *stat, rsa_key *key)
31 int rsa_decrypt_key_ex(const unsigned char *in, unsigned long inlen,
32 unsigned char *out, unsigned long *outlen,
33 const unsigned char *lparam, unsigned long lparamlen,
34 int hash_idx, int padding,
35 int *stat, const rsa_key *key)
3636 {
3737 unsigned long modulus_bitlen, modulus_bytelen, x;
3838 int err;
2929 @param key The RSA key to encrypt to
3030 @return CRYPT_OK if successful
3131 */
32 int rsa_encrypt_key_ex(const unsigned char *in, unsigned long inlen,
33 unsigned char *out, unsigned long *outlen,
34 const unsigned char *lparam, unsigned long lparamlen,
35 prng_state *prng, int prng_idx, int hash_idx, int padding, rsa_key *key)
32 int rsa_encrypt_key_ex(const unsigned char *in, unsigned long inlen,
33 unsigned char *out, unsigned long *outlen,
34 const unsigned char *lparam, unsigned long lparamlen,
35 prng_state *prng, int prng_idx,
36 int hash_idx, int padding,
37 const rsa_key *key)
3638 {
3739 unsigned long modulus_bitlen, modulus_bytelen, x;
3840 int err;
2222 @param key The RSA key to export
2323 @return CRYPT_OK if successful
2424 */
25 int rsa_export(unsigned char *out, unsigned long *outlen, int type, rsa_key *key)
25 int rsa_export(unsigned char *out, unsigned long *outlen, int type, const rsa_key *key)
2626 {
2727 unsigned long zero=0;
2828 int err;
5757 unsigned char* tmp = NULL;
5858
5959 if (type & PK_STD) {
60 tmplen = (mp_count_bits(key->N)/8)*2+8;
60 tmplen = (unsigned long)(mp_count_bits(key->N) / 8) * 2 + 8;
6161 tmp = XMALLOC(tmplen);
6262 ptmplen = &tmplen;
6363 if (tmp == NULL) {
2727 */
2828 int rsa_exptmod(const unsigned char *in, unsigned long inlen,
2929 unsigned char *out, unsigned long *outlen, int which,
30 rsa_key *key)
30 const rsa_key *key)
3131 {
3232 void *tmp, *tmpa, *tmpb;
3333 #ifdef LTC_RSA_BLINDING
1919 @param key The RSA key
2020 @return The size in bytes of the RSA key or INT_MAX on error.
2121 */
22 int rsa_get_size(rsa_key *key)
22 int rsa_get_size(const rsa_key *key)
2323 {
2424 int ret = INT_MAX;
2525 LTC_ARGCHK(key != NULL);
113113
114114 /* check alg oid */
115115 if ((alg_seq[0].size != rsaoid.OIDlen) ||
116 XMEMCMP(rsaoid.OID, alg_seq[0].data, rsaoid.OIDlen * sizeof(rsaoid.OID[0]))) {
116 XMEMCMP(rsaoid.OID, alg_seq[0].data, rsaoid.OIDlen * sizeof(rsaoid.OID[0])) != 0) {
117117 err = CRYPT_PK_INVALID_TYPE;
118118 goto LBL_ERR;
119119 }
3333 int padding,
3434 prng_state *prng, int prng_idx,
3535 int hash_idx, unsigned long saltlen,
36 rsa_key *key)
36 const rsa_key *key)
3737 {
3838 unsigned long modulus_bitlen, modulus_bytelen, x, y;
3939 int err;
2121 @param key The RSA key
2222 @return The maximum salt length in bytes or INT_MAX on error.
2323 */
24 int rsa_sign_saltlen_get_max_ex(int padding, int hash_idx, rsa_key *key)
24 int rsa_sign_saltlen_get_max_ex(int padding, int hash_idx, const rsa_key *key)
2525 {
2626 int ret = INT_MAX;
2727 LTC_ARGCHK(key != NULL);
2727 @param key The public RSA key corresponding to the key that performed the signature
2828 @return CRYPT_OK on success (even if the signature is invalid)
2929 */
30 int rsa_verify_hash_ex(const unsigned char *sig, unsigned long siglen,
31 const unsigned char *hash, unsigned long hashlen,
30 int rsa_verify_hash_ex(const unsigned char *sig, unsigned long siglen,
31 const unsigned char *hash, unsigned long hashlen,
3232 int padding,
33 int hash_idx, unsigned long saltlen,
34 int *stat, rsa_key *key)
33 int hash_idx, unsigned long saltlen,
34 int *stat, const rsa_key *key)
3535 {
3636 unsigned long modulus_bitlen, modulus_bytelen, x;
3737 int err;
6060 }
6161 }
6262
63 #ifdef LTC_FORTUNA_RESEED_RATELIMIT_TIMED
64 /* get the current time in 100ms steps */
65 static ulong64 _fortuna_current_time(void)
66 {
67 ulong64 cur_time;
68 #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L
69 struct timespec ts;
70 clock_gettime(CLOCK_MONOTONIC, &ts);
71 cur_time = (ulong64)(ts.tv_sec) * 1000000 + (ulong64)(ts.tv_nsec) / 1000; /* get microseconds */
72 #elif defined(_WIN32)
73 FILETIME CurrentTime;
74 ULARGE_INTEGER ul;
75 GetSystemTimeAsFileTime(&CurrentTime);
76 ul.LowPart = CurrentTime.dwLowDateTime;
77 ul.HighPart = CurrentTime.dwHighDateTime;
78 cur_time = ul.QuadPart;
79 cur_time -= CONST64(116444736000000000); /* subtract epoch in microseconds */
80 cur_time /= 1000; /* nanoseconds -> microseconds */
81 #endif
82 return cur_time / 100;
83 }
84 #endif
85
6386 /* reseed the PRNG */
6487 static int _fortuna_reseed(prng_state *prng)
6588 {
6891 ulong64 reset_cnt;
6992 int err, x;
7093
94 #ifdef LTC_FORTUNA_RESEED_RATELIMIT_TIMED
95 unsigned long now = _fortuna_current_time();
96 if (now == prng->fortuna.wd)
97 return CRYPT_OK;
98 #else
99 if (++prng->fortuna.wd < LTC_FORTUNA_WD)
100 return CRYPT_OK;
101 #endif
71102
72103 /* new K == LTC_SHA256(K || s) where s == LTC_SHA256(P0) || LTC_SHA256(P1) ... */
73104 sha256_init(&md);
111142
112143 /* reset/update internals */
113144 prng->fortuna.pool0_len = 0;
145 #ifdef LTC_FORTUNA_RESEED_RATELIMIT_TIMED
146 prng->fortuna.wd = now;
147 #else
114148 prng->fortuna.wd = 0;
149 #endif
115150 prng->fortuna.reset_cnt = reset_cnt;
116151
117152
131166 @param prng The PRNG to import
132167 @return CRYPT_OK if successful
133168 */
134 static int _fortuna_update_seed(const unsigned char *in, unsigned long inlen, prng_state *prng)
169 int fortuna_update_seed(const unsigned char *in, unsigned long inlen, prng_state *prng)
135170 {
136171 int err;
137172 unsigned char tmp[MAXBLOCKSIZE];
203238 return CRYPT_OK;
204239 }
205240
241 static int _fortuna_add(unsigned long source, unsigned long pool, const unsigned char *in, unsigned long inlen, prng_state *prng)
242 {
243 unsigned char tmp[2];
244 int err;
245
246 /* ensure inlen <= 32 */
247 if (inlen > 32) {
248 inlen = 32;
249 }
250
251 /* add s || length(in) || in to pool[pool_idx] */
252 tmp[0] = (unsigned char)source;
253 tmp[1] = (unsigned char)inlen;
254
255 if ((err = sha256_process(&prng->fortuna.pool[pool], tmp, 2)) != CRYPT_OK) {
256 return err;
257 }
258 if ((err = sha256_process(&prng->fortuna.pool[pool], in, inlen)) != CRYPT_OK) {
259 return err;
260 }
261 if (pool == 0) {
262 prng->fortuna.pool0_len += inlen;
263 }
264 return CRYPT_OK; /* success */
265 }
266
267 /**
268 Add random event to the PRNG state as proposed by the original paper.
269 @param source The source this random event comes from (0 .. 255)
270 @param pool The pool where to add the data to (0 .. LTC_FORTUNA_POOLS)
271 @param in The data to add
272 @param inlen Length of the data to add
273 @param prng PRNG state to update
274 @return CRYPT_OK if successful
275 */
276 int fortuna_add_random_event(unsigned long source, unsigned long pool, const unsigned char *in, unsigned long inlen, prng_state *prng)
277 {
278 int err;
279
280 LTC_ARGCHK(prng != NULL);
281 LTC_ARGCHK(in != NULL);
282 LTC_ARGCHK(inlen > 0);
283 LTC_ARGCHK(source <= 255);
284 LTC_ARGCHK(pool < LTC_FORTUNA_POOLS);
285
286 LTC_MUTEX_LOCK(&prng->lock);
287
288 err = _fortuna_add(source, pool, in, inlen, prng);
289
290 LTC_MUTEX_UNLOCK(&prng->lock);
291
292 return err;
293 }
294
206295 /**
207296 Add entropy to the PRNG state
208297 @param in The data to add
212301 */
213302 int fortuna_add_entropy(const unsigned char *in, unsigned long inlen, prng_state *prng)
214303 {
215 unsigned char tmp[2];
216 int err;
304 int err;
217305
218306 LTC_ARGCHK(prng != NULL);
219307 LTC_ARGCHK(in != NULL);
220308 LTC_ARGCHK(inlen > 0);
221309
222 /* ensure inlen <= 32 */
223 if (inlen > 32) {
224 inlen = 32;
225 }
226
227 /* add s || length(in) || in to pool[pool_idx] */
228 tmp[0] = 0;
229 tmp[1] = (unsigned char)inlen;
230
231310 LTC_MUTEX_LOCK(&prng->lock);
232 if ((err = sha256_process(&prng->fortuna.pool[prng->fortuna.pool_idx], tmp, 2)) != CRYPT_OK) {
233 goto LBL_UNLOCK;
234 }
235 if ((err = sha256_process(&prng->fortuna.pool[prng->fortuna.pool_idx], in, inlen)) != CRYPT_OK) {
236 goto LBL_UNLOCK;
237 }
238 if (prng->fortuna.pool_idx == 0) {
239 prng->fortuna.pool0_len += inlen;
240 }
241 if (++(prng->fortuna.pool_idx) == LTC_FORTUNA_POOLS) {
242 prng->fortuna.pool_idx = 0;
243 }
244 err = CRYPT_OK; /* success */
245
246 LBL_UNLOCK:
311
312 err = _fortuna_add(0, prng->fortuna.pool_idx, in, inlen, prng);
313
314 if (err == CRYPT_OK) {
315 ++(prng->fortuna.pool_idx);
316 prng->fortuna.pool_idx %= LTC_FORTUNA_POOLS;
317 }
318
247319 LTC_MUTEX_UNLOCK(&prng->lock);
320
248321 return err;
249322 }
250323
259332 LTC_ARGCHK(prng != NULL);
260333
261334 LTC_MUTEX_LOCK(&prng->lock);
335 /* make sure the reseed doesn't fail because
336 * of the chosen rate limit */
337 #ifdef LTC_FORTUNA_RESEED_RATELIMIT_TIMED
338 prng->fortuna.wd = _fortuna_current_time() - 1;
339 #else
340 prng->fortuna.wd = LTC_FORTUNA_WD;
341 #endif
262342 err = _fortuna_reseed(prng);
263343 prng->ready = (err == CRYPT_OK) ? 1 : 0;
264344
287367 }
288368
289369 /* do we have to reseed? */
290 if (++prng->fortuna.wd == LTC_FORTUNA_WD || prng->fortuna.pool0_len >= 64) {
370 if (prng->fortuna.pool0_len >= 64) {
291371 if (_fortuna_reseed(prng) != CRYPT_OK) {
292372 goto LBL_UNLOCK;
293373 }
400480 return err;
401481 }
402482
403 if ((err = _fortuna_update_seed(in, inlen, prng)) != CRYPT_OK) {
483 if ((err = fortuna_update_seed(in, inlen, prng)) != CRYPT_OK) {
404484 return err;
405485 }
406486
2727
2828 #define B(x,i) ((unsigned char)(((x) >> (8*i)) & 0xFF))
2929
30 static ulong32 BYTE2WORD(unsigned char *b)
30 static ulong32 BYTE2WORD(const unsigned char *b)
3131 {
3232 ulong32 t;
3333 LOAD32L(t, b);
7777 t = t + c->R[OFF(z,13)]; \
7878 }
7979
80 static ulong32 nltap(sober128_state *c)
80 static ulong32 nltap(const sober128_state *c)
8181 {
8282 ulong32 t;
8383 NLFUNC(c, 0);
200200 * @param keylen Length of key in bytes
201201 * @return CRYPT_OK on success
202202 */
203 int sosemanuk_setup(sosemanuk_state *ss, unsigned char *key, unsigned long keylen)
203 int sosemanuk_setup(sosemanuk_state *ss, const unsigned char *key, unsigned long keylen)
204204 {
205205 /*
206206 * This key schedule is actually a truncated Serpent key schedule.
340340 * @param ivlen Length of iv in bytes
341341 * @return CRYPT_OK on success
342342 */
343 int sosemanuk_setiv(sosemanuk_state *ss, unsigned char *iv, unsigned long ivlen)
343 int sosemanuk_setiv(sosemanuk_state *ss, const unsigned char *iv, unsigned long ivlen)
344344 {
345345
346346 /*