Mercurial > dropbear
comparison libtomcrypt/src/modes/f8/f8_encrypt.c @ 1511:5916af64acd4 fuzz
merge from main
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 17 Feb 2018 19:29:51 +0800 |
parents | 6dba84798cd5 |
children |
comparison
equal
deleted
inserted
replaced
1457:32f990cc96b1 | 1511:5916af64acd4 |
---|---|
3 * LibTomCrypt is a library that provides various cryptographic | 3 * LibTomCrypt is a library that provides various cryptographic |
4 * algorithms in a highly modular and flexible manner. | 4 * algorithms in a highly modular and flexible manner. |
5 * | 5 * |
6 * The library is free for all purposes without any express | 6 * The library is free for all purposes without any express |
7 * guarantee it works. | 7 * guarantee it works. |
8 * | |
9 * Tom St Denis, [email protected], http://libtom.org | |
10 */ | 8 */ |
11 #include "tomcrypt.h" | 9 #include "tomcrypt.h" |
12 | 10 |
13 /** | 11 /** |
14 @file f8_encrypt.c | 12 @file f8_encrypt.c |
33 LTC_ARGCHK(ct != NULL); | 31 LTC_ARGCHK(ct != NULL); |
34 LTC_ARGCHK(f8 != NULL); | 32 LTC_ARGCHK(f8 != NULL); |
35 if ((err = cipher_is_valid(f8->cipher)) != CRYPT_OK) { | 33 if ((err = cipher_is_valid(f8->cipher)) != CRYPT_OK) { |
36 return err; | 34 return err; |
37 } | 35 } |
38 | 36 |
39 /* is blocklen/padlen valid? */ | 37 /* is blocklen/padlen valid? */ |
40 if (f8->blocklen < 0 || f8->blocklen > (int)sizeof(f8->IV) || | 38 if (f8->blocklen < 0 || f8->blocklen > (int)sizeof(f8->IV) || |
41 f8->padlen < 0 || f8->padlen > (int)sizeof(f8->IV)) { | 39 f8->padlen < 0 || f8->padlen > (int)sizeof(f8->IV)) { |
42 return CRYPT_INVALID_ARG; | 40 return CRYPT_INVALID_ARG; |
43 } | 41 } |
44 | 42 |
45 zeromem(buf, sizeof(buf)); | 43 zeromem(buf, sizeof(buf)); |
46 | 44 |
47 /* make sure the pad is empty */ | 45 /* make sure the pad is empty */ |
48 if (f8->padlen == f8->blocklen) { | 46 if (f8->padlen == f8->blocklen) { |
49 /* xor of IV, MIV and blockcnt == what goes into cipher */ | 47 /* xor of IV, MIV and blockcnt == what goes into cipher */ |
62 if (f8->padlen == 0) { | 60 if (f8->padlen == 0) { |
63 while (len >= (unsigned long)f8->blocklen) { | 61 while (len >= (unsigned long)f8->blocklen) { |
64 STORE32H(f8->blockcnt, (buf+(f8->blocklen-4))); | 62 STORE32H(f8->blockcnt, (buf+(f8->blocklen-4))); |
65 ++(f8->blockcnt); | 63 ++(f8->blockcnt); |
66 for (x = 0; x < f8->blocklen; x += sizeof(LTC_FAST_TYPE)) { | 64 for (x = 0; x < f8->blocklen; x += sizeof(LTC_FAST_TYPE)) { |
67 *((LTC_FAST_TYPE*)(&ct[x])) = *((LTC_FAST_TYPE*)(&pt[x])) ^ *((LTC_FAST_TYPE*)(&f8->IV[x])); | 65 *(LTC_FAST_TYPE_PTR_CAST(&ct[x])) = *(LTC_FAST_TYPE_PTR_CAST(&pt[x])) ^ *(LTC_FAST_TYPE_PTR_CAST(&f8->IV[x])); |
68 *((LTC_FAST_TYPE*)(&f8->IV[x])) ^= *((LTC_FAST_TYPE*)(&f8->MIV[x])) ^ *((LTC_FAST_TYPE*)(&buf[x])); | 66 *(LTC_FAST_TYPE_PTR_CAST(&f8->IV[x])) ^= *(LTC_FAST_TYPE_PTR_CAST(&f8->MIV[x])) ^ *(LTC_FAST_TYPE_PTR_CAST(&buf[x])); |
69 } | 67 } |
70 if ((err = cipher_descriptor[f8->cipher].ecb_encrypt(f8->IV, f8->IV, &f8->key)) != CRYPT_OK) { | 68 if ((err = cipher_descriptor[f8->cipher].ecb_encrypt(f8->IV, f8->IV, &f8->key)) != CRYPT_OK) { |
71 return err; | 69 return err; |
72 } | 70 } |
73 len -= x; | 71 len -= x; |
74 pt += x; | 72 pt += x; |
75 ct += x; | 73 ct += x; |
76 } | 74 } |
77 } | 75 } |
78 #endif | 76 #endif |
79 | 77 |
80 while (len > 0) { | 78 while (len > 0) { |
81 if (f8->padlen == f8->blocklen) { | 79 if (f8->padlen == f8->blocklen) { |
82 /* xor of IV, MIV and blockcnt == what goes into cipher */ | 80 /* xor of IV, MIV and blockcnt == what goes into cipher */ |
83 STORE32H(f8->blockcnt, (buf+(f8->blocklen-4))); | 81 STORE32H(f8->blockcnt, (buf+(f8->blocklen-4))); |
96 return CRYPT_OK; | 94 return CRYPT_OK; |
97 } | 95 } |
98 | 96 |
99 #endif | 97 #endif |
100 | 98 |
101 /* $Source$ */ | 99 /* ref: $Format:%D$ */ |
102 /* $Revision$ */ | 100 /* git commit: $Format:%H$ */ |
103 /* $Date$ */ | 101 /* commit time: $Format:%ai$ */ |