Mercurial > dropbear
comparison libtomcrypt/src/encauth/gcm/gcm_add_iv.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 | 9 |
12 /** | 10 /** |
13 @file gcm_add_iv.c | 11 @file gcm_add_iv.c |
14 GCM implementation, add IV data to the state, by Tom St Denis | 12 GCM implementation, add IV data to the state, by Tom St Denis |
22 @param gcm The GCM state | 20 @param gcm The GCM state |
23 @param IV The initial value data to add | 21 @param IV The initial value data to add |
24 @param IVlen The length of the IV | 22 @param IVlen The length of the IV |
25 @return CRYPT_OK on success | 23 @return CRYPT_OK on success |
26 */ | 24 */ |
27 int gcm_add_iv(gcm_state *gcm, | 25 int gcm_add_iv(gcm_state *gcm, |
28 const unsigned char *IV, unsigned long IVlen) | 26 const unsigned char *IV, unsigned long IVlen) |
29 { | 27 { |
30 unsigned long x, y; | 28 unsigned long x, y; |
31 int err; | 29 int err; |
32 | 30 |
37 | 35 |
38 /* must be in IV mode */ | 36 /* must be in IV mode */ |
39 if (gcm->mode != LTC_GCM_MODE_IV) { | 37 if (gcm->mode != LTC_GCM_MODE_IV) { |
40 return CRYPT_INVALID_ARG; | 38 return CRYPT_INVALID_ARG; |
41 } | 39 } |
42 | 40 |
43 if (gcm->buflen >= 16 || gcm->buflen < 0) { | 41 if (gcm->buflen >= 16 || gcm->buflen < 0) { |
44 return CRYPT_INVALID_ARG; | 42 return CRYPT_INVALID_ARG; |
45 } | 43 } |
46 | 44 |
47 if ((err = cipher_is_valid(gcm->cipher)) != CRYPT_OK) { | 45 if ((err = cipher_is_valid(gcm->cipher)) != CRYPT_OK) { |
57 x = 0; | 55 x = 0; |
58 #ifdef LTC_FAST | 56 #ifdef LTC_FAST |
59 if (gcm->buflen == 0) { | 57 if (gcm->buflen == 0) { |
60 for (x = 0; x < (IVlen & ~15); x += 16) { | 58 for (x = 0; x < (IVlen & ~15); x += 16) { |
61 for (y = 0; y < 16; y += sizeof(LTC_FAST_TYPE)) { | 59 for (y = 0; y < 16; y += sizeof(LTC_FAST_TYPE)) { |
62 *((LTC_FAST_TYPE*)(&gcm->X[y])) ^= *((LTC_FAST_TYPE*)(&IV[x + y])); | 60 *(LTC_FAST_TYPE_PTR_CAST(&gcm->X[y])) ^= *(LTC_FAST_TYPE_PTR_CAST(&IV[x + y])); |
63 } | 61 } |
64 gcm_mult_h(gcm, gcm->X); | 62 gcm_mult_h(gcm, gcm->X); |
65 gcm->totlen += 128; | 63 gcm->totlen += 128; |
66 } | 64 } |
67 IV += x; | 65 IV += x; |
70 | 68 |
71 /* start adding IV data to the state */ | 69 /* start adding IV data to the state */ |
72 for (; x < IVlen; x++) { | 70 for (; x < IVlen; x++) { |
73 gcm->buf[gcm->buflen++] = *IV++; | 71 gcm->buf[gcm->buflen++] = *IV++; |
74 | 72 |
75 if (gcm->buflen == 16) { | 73 if (gcm->buflen == 16) { |
76 /* GF mult it */ | 74 /* GF mult it */ |
77 for (y = 0; y < 16; y++) { | 75 for (y = 0; y < 16; y++) { |
78 gcm->X[y] ^= gcm->buf[y]; | 76 gcm->X[y] ^= gcm->buf[y]; |
79 } | 77 } |
80 gcm_mult_h(gcm, gcm->X); | 78 gcm_mult_h(gcm, gcm->X); |
85 | 83 |
86 return CRYPT_OK; | 84 return CRYPT_OK; |
87 } | 85 } |
88 | 86 |
89 #endif | 87 #endif |
90 | |
91 | 88 |
92 /* $Source$ */ | 89 |
93 /* $Revision$ */ | 90 /* ref: $Format:%D$ */ |
94 /* $Date$ */ | 91 /* git commit: $Format:%H$ */ |
92 /* commit time: $Format:%ai$ */ |