Mercurial > dropbear
comparison libtomcrypt/src/mac/omac/omac_process.c @ 1471:6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Fri, 09 Feb 2018 21:44:05 +0800 |
parents | f849a5ca2efc |
children |
comparison
equal
deleted
inserted
replaced
1470:8bba51a55704 | 1471:6dba84798cd5 |
---|---|
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 omac_process.c | 12 @file omac_process.c |
15 LTC_OMAC1 support, process data, Tom St Denis | 13 OMAC1 support, process data, Tom St Denis |
16 */ | 14 */ |
17 | 15 |
18 | 16 |
19 #ifdef LTC_OMAC | 17 #ifdef LTC_OMAC |
20 | 18 |
21 /** | 19 /** |
22 Process data through LTC_OMAC | 20 Process data through OMAC |
23 @param omac The LTC_OMAC state | 21 @param omac The OMAC state |
24 @param in The input data to send through LTC_OMAC | 22 @param in The input data to send through OMAC |
25 @param inlen The length of the input (octets) | 23 @param inlen The length of the input (octets) |
26 @return CRYPT_OK if successful | 24 @return CRYPT_OK if successful |
27 */ | 25 */ |
28 int omac_process(omac_state *omac, const unsigned char *in, unsigned long inlen) | 26 int omac_process(omac_state *omac, const unsigned char *in, unsigned long inlen) |
29 { | 27 { |
30 unsigned long n, x, blklen; | 28 unsigned long n, x; |
31 int err; | 29 int err; |
32 | 30 |
33 LTC_ARGCHK(omac != NULL); | 31 LTC_ARGCHK(omac != NULL); |
34 LTC_ARGCHK(in != NULL); | 32 LTC_ARGCHK(in != NULL); |
35 if ((err = cipher_is_valid(omac->cipher_idx)) != CRYPT_OK) { | 33 if ((err = cipher_is_valid(omac->cipher_idx)) != CRYPT_OK) { |
40 (omac->blklen > (int)sizeof(omac->block)) || (omac->buflen > omac->blklen)) { | 38 (omac->blklen > (int)sizeof(omac->block)) || (omac->buflen > omac->blklen)) { |
41 return CRYPT_INVALID_ARG; | 39 return CRYPT_INVALID_ARG; |
42 } | 40 } |
43 | 41 |
44 #ifdef LTC_FAST | 42 #ifdef LTC_FAST |
45 blklen = cipher_descriptor[omac->cipher_idx].block_length; | 43 { |
46 if (omac->buflen == 0 && inlen > blklen) { | 44 unsigned long blklen = cipher_descriptor[omac->cipher_idx].block_length; |
47 unsigned long y; | 45 |
48 for (x = 0; x < (inlen - blklen); x += blklen) { | 46 if (omac->buflen == 0 && inlen > blklen) { |
49 for (y = 0; y < blklen; y += sizeof(LTC_FAST_TYPE)) { | 47 unsigned long y; |
50 *((LTC_FAST_TYPE*)(&omac->prev[y])) ^= *((LTC_FAST_TYPE*)(&in[y])); | 48 for (x = 0; x < (inlen - blklen); x += blklen) { |
51 } | 49 for (y = 0; y < blklen; y += sizeof(LTC_FAST_TYPE)) { |
52 in += blklen; | 50 *(LTC_FAST_TYPE_PTR_CAST(&omac->prev[y])) ^= *(LTC_FAST_TYPE_PTR_CAST(&in[y])); |
53 if ((err = cipher_descriptor[omac->cipher_idx].ecb_encrypt(omac->prev, omac->prev, &omac->key)) != CRYPT_OK) { | 51 } |
54 return err; | 52 in += blklen; |
55 } | 53 if ((err = cipher_descriptor[omac->cipher_idx].ecb_encrypt(omac->prev, omac->prev, &omac->key)) != CRYPT_OK) { |
56 } | 54 return err; |
57 inlen -= x; | 55 } |
58 } | 56 } |
57 inlen -= x; | |
58 } | |
59 } | |
59 #endif | 60 #endif |
60 | 61 |
61 while (inlen != 0) { | 62 while (inlen != 0) { |
62 /* ok if the block is full we xor in prev, encrypt and replace prev */ | 63 /* ok if the block is full we xor in prev, encrypt and replace prev */ |
63 if (omac->buflen == omac->blklen) { | 64 if (omac->buflen == omac->blklen) { |
64 for (x = 0; x < (unsigned long)omac->blklen; x++) { | 65 for (x = 0; x < (unsigned long)omac->blklen; x++) { |
65 omac->block[x] ^= omac->prev[x]; | 66 omac->block[x] ^= omac->prev[x]; |
66 } | 67 } |
82 } | 83 } |
83 | 84 |
84 #endif | 85 #endif |
85 | 86 |
86 | 87 |
87 /* $Source$ */ | 88 /* ref: $Format:%D$ */ |
88 /* $Revision$ */ | 89 /* git commit: $Format:%H$ */ |
89 /* $Date$ */ | 90 /* commit time: $Format:%ai$ */ |