comparison ocb_encrypt.c @ 0:d7da3b1e1540 libtomcrypt

put back the 0.95 makefile which was inadvertently merged over
author Matt Johnston <matt@ucc.asn.au>
date Mon, 31 May 2004 18:21:40 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:d7da3b1e1540
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_encrypt(ocb_state *ocb, const unsigned char *pt, unsigned char *ct)
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 /* compute checksum */
33 for (x = 0; x < ocb->block_len; x++) {
34 ocb->checksum[x] ^= pt[x];
35 }
36
37 /* Get Z[i] value */
38 ocb_shift_xor(ocb, Z);
39
40 /* xor pt in, encrypt, xor Z out */
41 for (x = 0; x < ocb->block_len; x++) {
42 tmp[x] = pt[x] ^ Z[x];
43 }
44 cipher_descriptor[ocb->cipher].ecb_encrypt(tmp, ct, &ocb->key);
45 for (x = 0; x < ocb->block_len; x++) {
46 ct[x] ^= Z[x];
47 }
48
49 #ifdef CLEAN_STACK
50 zeromem(Z, sizeof(Z));
51 zeromem(tmp, sizeof(tmp));
52 #endif
53 return CRYPT_OK;
54 }
55
56 #endif