monotone

monotone Mtn Source Tree

Root/botan/symkey.h

1/*************************************************
2* OctetString Header File *
3* (C) 1999-2005 The Botan Project *
4*************************************************/
5
6#ifndef BOTAN_SYMKEY_H__
7#define BOTAN_SYMKEY_H__
8
9#include <botan/secmem.h>
10#include <botan/enums.h>
11#include <string>
12
13namespace Botan {
14
15/*************************************************
16* Octet String *
17*************************************************/
18class OctetString
19 {
20 public:
21 u32bit length() const { return bits.size(); }
22 SecureVector<byte> bits_of() const { return bits; }
23
24 const byte* begin() const { return bits.begin(); }
25 const byte* end() const { return bits.end(); }
26
27 std::string as_string() const;
28
29 OctetString& operator^=(const OctetString&);
30
31 void set_odd_parity();
32
33 void change(u32bit, RNG_Quality);
34 void change(const std::string&);
35 void change(const byte[], u32bit);
36 void change(const MemoryRegion<byte>& in) { bits = in; }
37
38 OctetString(const std::string& str = "") { change(str); }
39 OctetString(const byte in[], u32bit len) { change(in, len); }
40 OctetString(const MemoryRegion<byte>& in) { change(in); }
41 private:
42 SecureVector<byte> bits;
43 };
44
45/*************************************************
46* Operations on Octet Strings *
47*************************************************/
48bool operator==(const OctetString&, const OctetString&);
49bool operator!=(const OctetString&, const OctetString&);
50OctetString operator+(const OctetString&, const OctetString&);
51OctetString operator^(const OctetString&, const OctetString&);
52
53/*************************************************
54* Symmetric Key *
55*************************************************/
56class SymmetricKey : public OctetString
57 {
58 public:
59 void change(u32bit n) { OctetString::change(n, SessionKey); }
60 SymmetricKey(u32bit len) { change(len); }
61 SymmetricKey(const std::string& str = "") : OctetString(str) {}
62 SymmetricKey(const byte in[], u32bit l) : OctetString(in, l) {}
63 SymmetricKey(const MemoryRegion<byte>& in) : OctetString(in) {}
64 SymmetricKey(const OctetString& os) : OctetString(os) {}
65 };
66
67/*************************************************
68* Initialization Vector *
69*************************************************/
70class InitializationVector : public OctetString
71 {
72 public:
73 void change(u32bit n) { OctetString::change(n, Nonce); }
74 InitializationVector(u32bit len) { change(len); }
75 InitializationVector(const std::string& str = "") : OctetString(str) {}
76 InitializationVector(const byte in[], u32bit l) : OctetString(in, l) {}
77 InitializationVector(const MemoryRegion<byte>& in) : OctetString(in) {}
78 InitializationVector(const OctetString& os) : OctetString(os) {}
79 };
80
81}
82
83#endif

Archive Download this file

Branches

Tags

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