1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner.
6 * The library is free for all purposes without any express
12 OCB implementation, encrypt data, by Tom St Denis
19 Encrypt a block of data with OCB.
20 @param ocb The OCB state
21 @param pt The plaintext (length of the block size of the block cipher)
22 @param ct [out] The ciphertext (same size as the pt)
23 @return CRYPT_OK if successful
25 int ocb_encrypt(ocb_state *ocb, const unsigned char *pt, unsigned char *ct)
27 unsigned char Z[MAXBLOCKSIZE], tmp[MAXBLOCKSIZE];
30 LTC_ARGCHK(ocb != NULL);
31 LTC_ARGCHK(pt != NULL);
32 LTC_ARGCHK(ct != NULL);
33 if ((err = cipher_is_valid(ocb->cipher)) != CRYPT_OK) {
36 if (ocb->block_len != cipher_descriptor[ocb->cipher].block_length) {
37 return CRYPT_INVALID_ARG;
40 /* compute checksum */
41 for (x = 0; x < ocb->block_len; x++) {
42 ocb->checksum[x] ^= pt[x];
46 ocb_shift_xor(ocb, Z);
48 /* xor pt in, encrypt, xor Z out */
49 for (x = 0; x < ocb->block_len; x++) {
50 tmp[x] = pt[x] ^ Z[x];
52 if ((err = cipher_descriptor[ocb->cipher].ecb_encrypt(tmp, ct, &ocb->key)) != CRYPT_OK) {
55 for (x = 0; x < ocb->block_len; x++) {
59 #ifdef LTC_CLEAN_STACK
60 zeromem(Z, sizeof(Z));
61 zeromem(tmp, sizeof(tmp));
68 /* ref: $Format:%D$ */
69 /* git commit: $Format:%H$ */
70 /* commit time: $Format:%ai$ */