Process data through XCBC-MAC @param xcbc The XCBC-MAC state @param in Input data to process @param inlen Length of input in octets Return CRYPT_OK on success */
| 22 | Return CRYPT_OK on success |
| 23 | */ |
| 24 | int xcbc_process(xcbc_state *xcbc, const unsigned char *in, unsigned long inlen) |
| 25 | { |
| 26 | int err; |
| 27 | #ifdef LTC_FAST |
| 28 | int x; |
| 29 | #endif |
| 30 | |
| 31 | LTC_ARGCHK(xcbc != NULL); |
| 32 | LTC_ARGCHK(in != NULL); |
| 33 | |
| 34 | /* check structure */ |
| 35 | if ((err = cipher_is_valid(xcbc->cipher)) != CRYPT_OK) { |
| 36 | return err; |
| 37 | } |
| 38 | |
| 39 | if ((xcbc->blocksize > cipher_descriptor[xcbc->cipher].block_length) || (xcbc->blocksize < 0) || |
| 40 | (xcbc->buflen > xcbc->blocksize) || (xcbc->buflen < 0)) { |
| 41 | return CRYPT_INVALID_ARG; |
| 42 | } |
| 43 | |
| 44 | #ifdef LTC_FAST |
| 45 | if (xcbc->buflen == 0) { |
| 46 | while (inlen > (unsigned long)xcbc->blocksize) { |
| 47 | for (x = 0; x < xcbc->blocksize; x += sizeof(LTC_FAST_TYPE)) { |
| 48 | *(LTC_FAST_TYPE_PTR_CAST(&(xcbc->IV[x]))) ^= *(LTC_FAST_TYPE_PTR_CAST(&(in[x]))); |
| 49 | } |
| 50 | cipher_descriptor[xcbc->cipher].ecb_encrypt(xcbc->IV, xcbc->IV, &xcbc->key); |
| 51 | in += xcbc->blocksize; |
| 52 | inlen -= xcbc->blocksize; |
| 53 | } |
| 54 | } |
| 55 | #endif |
| 56 | |
| 57 | while (inlen) { |
| 58 | if (xcbc->buflen == xcbc->blocksize) { |
| 59 | cipher_descriptor[xcbc->cipher].ecb_encrypt(xcbc->IV, xcbc->IV, &xcbc->key); |
| 60 | xcbc->buflen = 0; |
| 61 | } |
| 62 | xcbc->IV[xcbc->buflen++] ^= *in++; |
| 63 | --inlen; |
| 64 | } |
| 65 | return CRYPT_OK; |
| 66 | } |
| 67 | |
| 68 | #endif |
| 69 |
no test coverage detected