Mercurial > dropbear
comparison libtomcrypt/src/encauth/ocb/ocb_encrypt.c @ 285:1b9e69c058d2
propagate from branch 'au.asn.ucc.matt.ltc.dropbear' (head 20dccfc09627970a312d77fb41dc2970b62689c3)
to branch 'au.asn.ucc.matt.dropbear' (head fdf4a7a3b97ae5046139915de7e40399cceb2c01)
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 08 Mar 2006 13:23:58 +0000 |
parents | |
children | 0cbe8f6dbf9e |
comparison
equal
deleted
inserted
replaced
281:997e6f7dc01e | 285:1b9e69c058d2 |
---|---|
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.org | |
10 */ | |
11 | |
12 /** | |
13 @file ocb_encrypt.c | |
14 OCB implementation, encrypt data, by Tom St Denis | |
15 */ | |
16 #include "tomcrypt.h" | |
17 | |
18 #ifdef OCB_MODE | |
19 | |
20 /** | |
21 Encrypt a block of data with OCB. | |
22 @param ocb The OCB state | |
23 @param pt The plaintext (length of the block size of the block cipher) | |
24 @param ct [out] The ciphertext (same size as the pt) | |
25 @return CRYPT_OK if successful | |
26 */ | |
27 int ocb_encrypt(ocb_state *ocb, const unsigned char *pt, unsigned char *ct) | |
28 { | |
29 unsigned char Z[MAXBLOCKSIZE], tmp[MAXBLOCKSIZE]; | |
30 int err, x; | |
31 | |
32 LTC_ARGCHK(ocb != NULL); | |
33 LTC_ARGCHK(pt != NULL); | |
34 LTC_ARGCHK(ct != NULL); | |
35 if ((err = cipher_is_valid(ocb->cipher)) != CRYPT_OK) { | |
36 return err; | |
37 } | |
38 if (ocb->block_len != cipher_descriptor[ocb->cipher].block_length) { | |
39 return CRYPT_INVALID_ARG; | |
40 } | |
41 | |
42 /* compute checksum */ | |
43 for (x = 0; x < ocb->block_len; x++) { | |
44 ocb->checksum[x] ^= pt[x]; | |
45 } | |
46 | |
47 /* Get Z[i] value */ | |
48 ocb_shift_xor(ocb, Z); | |
49 | |
50 /* xor pt in, encrypt, xor Z out */ | |
51 for (x = 0; x < ocb->block_len; x++) { | |
52 tmp[x] = pt[x] ^ Z[x]; | |
53 } | |
54 cipher_descriptor[ocb->cipher].ecb_encrypt(tmp, ct, &ocb->key); | |
55 for (x = 0; x < ocb->block_len; x++) { | |
56 ct[x] ^= Z[x]; | |
57 } | |
58 | |
59 #ifdef LTC_CLEAN_STACK | |
60 zeromem(Z, sizeof(Z)); | |
61 zeromem(tmp, sizeof(tmp)); | |
62 #endif | |
63 return CRYPT_OK; | |
64 } | |
65 | |
66 #endif | |
67 | |
68 /* $Source: /cvs/libtom/libtomcrypt/src/encauth/ocb/ocb_encrypt.c,v $ */ | |
69 /* $Revision: 1.3 $ */ | |
70 /* $Date: 2005/05/05 14:35:58 $ */ |