Mercurial > dropbear
comparison ocb_decrypt.c @ 3:7faae8f46238 libtomcrypt-orig
Branch renaming
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Mon, 31 May 2004 18:25:41 +0000 |
parents | |
children | 6362d3854bb4 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 3:7faae8f46238 |
---|---|
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 /* OCB Implementation by Tom St Denis */ | |
13 #include "mycrypt.h" | |
14 | |
15 #ifdef OCB_MODE | |
16 | |
17 int ocb_decrypt(ocb_state *ocb, const unsigned char *ct, unsigned char *pt) | |
18 { | |
19 unsigned char Z[MAXBLOCKSIZE], tmp[MAXBLOCKSIZE]; | |
20 int err, x; | |
21 | |
22 _ARGCHK(ocb != NULL); | |
23 _ARGCHK(pt != NULL); | |
24 _ARGCHK(ct != NULL); | |
25 if ((err = cipher_is_valid(ocb->cipher)) != CRYPT_OK) { | |
26 return err; | |
27 } | |
28 if (ocb->block_len != cipher_descriptor[ocb->cipher].block_length) { | |
29 return CRYPT_INVALID_ARG; | |
30 } | |
31 | |
32 /* Get Z[i] value */ | |
33 ocb_shift_xor(ocb, Z); | |
34 | |
35 /* xor ct in, encrypt, xor Z out */ | |
36 for (x = 0; x < ocb->block_len; x++) { | |
37 tmp[x] = ct[x] ^ Z[x]; | |
38 } | |
39 cipher_descriptor[ocb->cipher].ecb_decrypt(tmp, pt, &ocb->key); | |
40 for (x = 0; x < ocb->block_len; x++) { | |
41 pt[x] ^= Z[x]; | |
42 } | |
43 | |
44 /* compute checksum */ | |
45 for (x = 0; x < ocb->block_len; x++) { | |
46 ocb->checksum[x] ^= pt[x]; | |
47 } | |
48 | |
49 | |
50 #ifdef CLEAN_STACK | |
51 zeromem(Z, sizeof(Z)); | |
52 zeromem(tmp, sizeof(tmp)); | |
53 #endif | |
54 return CRYPT_OK; | |
55 } | |
56 | |
57 #endif | |
58 |