1
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
3
* LibTomCrypt is a library that provides various cryptographic
4
* algorithms in a highly modular and flexible manner.
6
* The library is free for all purposes without any express
9
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
14
GCM implementation, add IV data to the state, by Tom St Denis
21
Add IV data to the GCM state
22
@param gcm The GCM state
23
@param IV The initial value data to add
24
@param IVlen The length of the IV
25
@return CRYPT_OK on success
27
int gcm_add_iv(gcm_state *gcm,
28
const unsigned char *IV, unsigned long IVlen)
33
LTC_ARGCHK(gcm != NULL);
35
LTC_ARGCHK(IV != NULL);
38
/* must be in IV mode */
39
if (gcm->mode != GCM_MODE_IV) {
40
return CRYPT_INVALID_ARG;
43
if (gcm->buflen >= 16 || gcm->buflen < 0) {
44
return CRYPT_INVALID_ARG;
47
if ((err = cipher_is_valid(gcm->cipher)) != CRYPT_OK) {
52
/* trip the ivmode flag */
53
if (IVlen + gcm->buflen > 12) {
59
if (gcm->buflen == 0) {
60
for (x = 0; x < (IVlen & ~15); x += 16) {
61
for (y = 0; y < 16; y += sizeof(LTC_FAST_TYPE)) {
62
*((LTC_FAST_TYPE*)(&gcm->X[y])) ^= *((LTC_FAST_TYPE*)(&IV[x + y]));
64
gcm_mult_h(gcm, gcm->X);
71
/* start adding IV data to the state */
72
for (; x < IVlen; x++) {
73
gcm->buf[gcm->buflen++] = *IV++;
75
if (gcm->buflen == 16) {
77
for (y = 0; y < 16; y++) {
78
gcm->X[y] ^= gcm->buf[y];
80
gcm_mult_h(gcm, gcm->X);
92
/* $Source: /cvs/libtom/libtomcrypt/src/encauth/gcm/gcm_add_iv.c,v $ */
93
/* $Revision: 1.6 $ */
94
/* $Date: 2005/05/05 14:35:58 $ */