monotone

monotone Mtn Source Tree

Root/botan/ofb.cpp

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

Archive Download this file

Branches

Tags

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