monotone

monotone Mtn Source Tree

Root/botan/filters.cpp

1/*************************************************
2* Filters Source File *
3* (C) 1999-2005 The Botan Project *
4*************************************************/
5
6#include <botan/filters.h>
7#include <botan/lookup.h>
8
9namespace Botan {
10
11/*************************************************
12* StreamCipher_Filter Constructor *
13*************************************************/
14StreamCipher_Filter::StreamCipher_Filter(const std::string& sc_name) :
15 buffer(DEFAULT_BUFFERSIZE)
16 {
17 base_ptr = cipher = get_stream_cipher(sc_name);
18 }
19
20/*************************************************
21* Set the IV of a stream cipher *
22*************************************************/
23void StreamCipher_Filter::set_iv(const InitializationVector& iv)
24 {
25 cipher->resync(iv.begin(), iv.length());
26 }
27
28/*************************************************
29* Write data into a StreamCipher_Filter *
30*************************************************/
31void StreamCipher_Filter::write(const byte input[], u32bit length)
32 {
33 while(length)
34 {
35 u32bit copied = std::min(length, buffer.size());
36 cipher->encrypt(input, buffer, copied);
37 send(buffer, copied);
38 input += copied;
39 length -= copied;
40 }
41 }
42
43/*************************************************
44* Hash_Filter Constructor *
45*************************************************/
46Hash_Filter::Hash_Filter(const std::string& hash_name, u32bit len) :
47 OUTPUT_LENGTH(len)
48 {
49 hash = get_hash(hash_name);
50 }
51
52/*************************************************
53* Complete a calculation by a Hash_Filter *
54*************************************************/
55void Hash_Filter::end_msg()
56 {
57 SecureVector<byte> output = hash->final();
58 if(OUTPUT_LENGTH)
59 send(output, std::min(OUTPUT_LENGTH, output.size()));
60 else
61 send(output);
62 }
63
64/*************************************************
65* MAC_Filter Constructor *
66*************************************************/
67MAC_Filter::MAC_Filter(const std::string& mac_name, u32bit len) :
68 OUTPUT_LENGTH(len)
69 {
70 base_ptr = mac = get_mac(mac_name);
71 }
72
73/*************************************************
74* MAC_Filter Constructor *
75*************************************************/
76MAC_Filter::MAC_Filter(const std::string& mac_name, const SymmetricKey& key,
77 u32bit len) : OUTPUT_LENGTH(len)
78 {
79 base_ptr = mac = get_mac(mac_name);
80 mac->set_key(key);
81 }
82
83/*************************************************
84* Complete a calculation by a MAC_Filter *
85*************************************************/
86void MAC_Filter::end_msg()
87 {
88 SecureVector<byte> output = mac->final();
89 if(OUTPUT_LENGTH)
90 send(output, std::min(OUTPUT_LENGTH, output.size()));
91 else
92 send(output);
93 }
94
95}

Archive Download this file

Branches

Tags

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