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
13 LRW_MODE implementation, Set the current IV, Tom St Denis
20 @param IV The IV, must be 16 octets
21 @param len Length ... must be 16 :-)
22 @param lrw The LRW state to update
23 @return CRYPT_OK if successful
25 int lrw_setiv(const unsigned char *IV, unsigned long len, symmetric_LRW *lrw)
32 LTC_ARGCHK(IV != NULL);
33 LTC_ARGCHK(lrw != NULL);
36 return CRYPT_INVALID_ARG;
39 if ((err = cipher_is_valid(lrw->cipher)) != CRYPT_OK) {
44 XMEMCPY(lrw->IV, IV, 16);
46 /* check if we have to actually do work */
47 if (cipher_descriptor[lrw->cipher].accel_lrw_encrypt != NULL && cipher_descriptor[lrw->cipher].accel_lrw_decrypt != NULL) {
48 /* we have accelerators, let's bail since they don't use lrw->pad anyways */
53 XMEMCPY(T, &lrw->PC[0][IV[0]][0], 16);
54 for (x = 1; x < 16; x++) {
56 for (y = 0; y < 16; y += sizeof(LTC_FAST_TYPE)) {
57 *(LTC_FAST_TYPE_PTR_CAST(T + y)) ^= *(LTC_FAST_TYPE_PTR_CAST(&lrw->PC[x][IV[x]][y]));
60 for (y = 0; y < 16; y++) {
61 T[y] ^= lrw->PC[x][IV[x]][y];
65 XMEMCPY(lrw->pad, T, 16);
67 gcm_gf_mult(lrw->tweak, IV, lrw->pad);
75 /* ref: $Format:%D$ */
76 /* git commit: $Format:%H$ */
77 /* commit time: $Format:%ai$ */