Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/libs/tomcrypt/src/mac/xcbc/xcbc_process.c
5972 views
1
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
2
*
3
* LibTomCrypt is a library that provides various cryptographic
4
* algorithms in a highly modular and flexible manner.
5
*
6
* The library is free for all purposes without any express
7
* guarantee it works.
8
*/
9
#include "tomcrypt.h"
10
11
/**
12
@file xcbc_process.c
13
XCBC Support, process blocks with XCBC
14
*/
15
16
#ifdef LTC_XCBC
17
18
/** Process data through XCBC-MAC
19
@param xcbc The XCBC-MAC state
20
@param in Input data to process
21
@param inlen Length of input in octets
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
70