comparison libtomcrypt/src/mac/xcbc/xcbc_process.c @ 382:0cbe8f6dbf9e

propagate from branch 'au.asn.ucc.matt.ltc.dropbear' (head 2af22fb4e878750b88f80f90d439b316d229796f) to branch 'au.asn.ucc.matt.dropbear' (head 02c413252c90e9de8e03d91e9939dde3029f5c0a)
author Matt Johnston <matt@ucc.asn.au>
date Thu, 11 Jan 2007 02:41:05 +0000
parents
children f849a5ca2efc
comparison
equal deleted inserted replaced
379:b66a00272a90 382:0cbe8f6dbf9e
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 * Tom St Denis, [email protected], http://libtomcrypt.com
10 */
11 #include "tomcrypt.h"
12
13 /**
14 @file xcbc_process.c
15 XCBC Support, process blocks with XCBC
16 */
17
18 #ifdef LTC_XCBC
19
20 /** Process data through XCBC-MAC
21 @param xcbc The XCBC-MAC state
22 @param in Input data to process
23 @param inlen Length of input in octets
24 Return CRYPT_OK on success
25 */
26 int xcbc_process(xcbc_state *xcbc, const unsigned char *in, unsigned long inlen)
27 {
28 int err;
29 #ifdef LTC_FAST
30 int x;
31 #endif
32
33 LTC_ARGCHK(xcbc != NULL);
34 LTC_ARGCHK(in != NULL);
35
36 /* check structure */
37 if ((err = cipher_is_valid(xcbc->cipher)) != CRYPT_OK) {
38 return err;
39 }
40
41 if ((xcbc->blocksize > cipher_descriptor[xcbc->cipher].block_length) || (xcbc->blocksize < 0) ||
42 (xcbc->buflen > xcbc->blocksize) || (xcbc->buflen < 0)) {
43 return CRYPT_INVALID_ARG;
44 }
45
46 #ifdef LTC_FAST
47 if (xcbc->buflen == 0) {
48 while (inlen > (unsigned long)xcbc->blocksize) {
49 for (x = 0; x < xcbc->blocksize; x += sizeof(LTC_FAST_TYPE)) {
50 *((LTC_FAST_TYPE*)&(xcbc->IV[x])) ^= *((LTC_FAST_TYPE*)&(in[x]));
51 }
52 cipher_descriptor[xcbc->cipher].ecb_encrypt(xcbc->IV, xcbc->IV, &xcbc->key);
53 in += xcbc->blocksize;
54 inlen -= xcbc->blocksize;
55 }
56 }
57 #endif
58
59 while (inlen) {
60 if (xcbc->buflen == xcbc->blocksize) {
61 cipher_descriptor[xcbc->cipher].ecb_encrypt(xcbc->IV, xcbc->IV, &xcbc->key);
62 xcbc->buflen = 0;
63 }
64 xcbc->IV[xcbc->buflen++] ^= *in++;
65 --inlen;
66 }
67 return CRYPT_OK;
68 }
69
70 #endif
71
72 /* $Source: /cvs/libtom/libtomcrypt/src/mac/xcbc/xcbc_process.c,v $ */
73 /* $Revision: 1.9 $ */
74 /* $Date: 2006/11/09 22:43:52 $ */
75