monotone

monotone Mtn Source Tree

Root/botan/ofb.cpp

1/*************************************************
2* OFB Mode Source File *
3* (C) 1999-2005 The Botan Project *
4*************************************************/
5
6#include <botan/ofb.h>
7#include <botan/lookup.h>
8#include <botan/bit_ops.h>
9
10namespace Botan {
11
12/*************************************************
13* OFB Constructor *
14*************************************************/
15OFB::OFB(const std::string& cipher_name) :
16 BlockCipherMode(cipher_name, "OFB", block_size_of(cipher_name), 2)
17 {
18 }
19
20/*************************************************
21* OFB Constructor *
22*************************************************/
23OFB::OFB(const std::string& cipher_name, const SymmetricKey& key,
24 const InitializationVector& iv) :
25 BlockCipherMode(cipher_name, "OFB", block_size_of(cipher_name), 2)
26 {
27 set_key(key);
28 set_iv(iv);
29 }
30
31/*************************************************
32* OFB Encryption/Decryption *
33*************************************************/
34void OFB::write(const byte input[], u32bit length)
35 {
36 u32bit copied = std::min(BLOCK_SIZE - position, length);
37 xor_buf(buffer, input, state + position, copied);
38 send(buffer, copied);
39 input += copied;
40 length -= copied;
41 position += copied;
42
43 if(position == BLOCK_SIZE)
44 {
45 cipher->encrypt(state);
46 position = 0;
47 }
48
49 while(length >= BLOCK_SIZE)
50 {
51 xor_buf(buffer, input, state, BLOCK_SIZE);
52 send(buffer, BLOCK_SIZE);
53
54 input += BLOCK_SIZE;
55 length -= BLOCK_SIZE;
56 cipher->encrypt(state);
57 }
58
59 xor_buf(buffer, input, state + position, length);
60 send(buffer, length);
61 position += length;
62 }
63
64}

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status