3
* (C) 1999-2007 Jack Lloyd
5
* Distributed under the terms of the Botan license
8
#ifndef BOTAN_BUFFERED_COMPUTATION_H__
9
#define BOTAN_BUFFERED_COMPUTATION_H__
11
#include <botan/secmem.h>
16
* This class represents any kind of computation which
17
* uses an internal state,
18
* such as hash functions.
20
class BOTAN_DLL BufferedComputation
25
* The length of the output of this function in bytes.
27
const u32bit OUTPUT_LENGTH;
30
* Add new input to process.
31
* @param in the input to process as a byte array
32
* @param the length of the byte array
34
void update(const byte in[], u32bit length) { add_data(in, length); }
37
* Add new input to process.
38
* @param in the input to process as a MemoryRegion
40
void update(const MemoryRegion<byte>& in) { add_data(in, in.size()); }
43
* Add new input to process.
44
* @param str the input to process as a std::string. Will be interpreted
45
* as a byte array based on
46
* the strings encoding.
48
void update(const std::string& str)
50
add_data(reinterpret_cast<const byte*>(str.data()), str.size());
54
* Process a single byte.
55
* @param in the byte to process
57
void update(byte in) { add_data(&in, 1); }
60
* Complete the computation and retrieve the
62
* @param out The byte array to be filled with the result.
63
* Must be of length OUTPUT_LENGTH.
65
void final(byte out[]) { final_result(out); }
68
* Complete the computation and retrieve the
70
* @return a SecureVector holding the result
72
SecureVector<byte> final()
74
SecureVector<byte> output(OUTPUT_LENGTH);
80
* Update and finalize computation. Does the same as calling update()
81
* and final() consecutively.
82
* @param in the input to process as a byte array
83
* @param length the length of the byte array
84
* @result the result of the call to final()
86
SecureVector<byte> process(const byte in[], u32bit length)
93
* Update and finalize computation. Does the same as calling update()
94
* and final() consecutively.
95
* @param in the input to process
96
* @result the result of the call to final()
98
SecureVector<byte> process(const MemoryRegion<byte>& in)
100
add_data(in, in.size());
105
* Update and finalize computation. Does the same as calling update()
106
* and final() consecutively.
107
* @param in the input to process as a string
108
* @result the result of the call to final()
110
SecureVector<byte> process(const std::string& in)
116
BufferedComputation(u32bit out_len) : OUTPUT_LENGTH(out_len) {}
117
virtual ~BufferedComputation() {}
119
BufferedComputation& operator=(const BufferedComputation&);
120
virtual void add_data(const byte[], u32bit) = 0;
121
virtual void final_result(byte[]) = 0;