monotone

monotone Mtn Source Tree

Root/botan/def_alg.cpp

1/*************************************************
2* Default Engine Algorithms Source File *
3* (C) 1999-2005 The Botan Project *
4*************************************************/
5
6#include <botan/def_eng.h>
7#include <botan/lookup.h>
8#include <botan/parsing.h>
9
10#include <botan/aes.h>
11#include <botan/des.h>
12
13#include <botan/arc4.h>
14
15#include <botan/crc32.h>
16#include <botan/sha160.h>
17#include <botan/sha256.h>
18
19#include <botan/hmac.h>
20
21namespace Botan {
22
23/*************************************************
24* Some macros to simplify control flow *
25*************************************************/
26#define HANDLE_TYPE_NO_ARGS(NAME, TYPE) \
27 if(algo_name == NAME) \
28 { \
29 if(name.size() == 1) \
30 return new TYPE; \
31 throw Invalid_Algorithm_Name(algo_spec); \
32 }
33
34#define HANDLE_TYPE_ONE_U32BIT(NAME, TYPE, DEFAULT) \
35 if(algo_name == NAME) \
36 { \
37 if(name.size() == 1) \
38 return new TYPE(DEFAULT); \
39 if(name.size() == 2) \
40 return new TYPE(to_u32bit(name[1])); \
41 throw Invalid_Algorithm_Name(algo_spec); \
42 }
43
44#define HANDLE_TYPE_TWO_U32BIT(NAME, TYPE, DEFAULT) \
45 if(algo_name == NAME) \
46 { \
47 if(name.size() == 1) \
48 return new TYPE(DEFAULT); \
49 if(name.size() == 2) \
50 return new TYPE(to_u32bit(name[1])); \
51 if(name.size() == 3) \
52 return new TYPE(to_u32bit(name[1]), to_u32bit(name[2])); \
53 throw Invalid_Algorithm_Name(algo_spec); \
54 }
55
56#define HANDLE_TYPE_ONE_STRING(NAME, TYPE) \
57 if(algo_name == NAME) \
58 { \
59 if(name.size() == 2) \
60 return new TYPE(name[1]); \
61 throw Invalid_Algorithm_Name(algo_spec); \
62 }
63
64/*************************************************
65* Look for an algorithm with this name *
66*************************************************/
67BlockCipher*
68Default_Engine::find_block_cipher(const std::string& algo_spec) const
69 {
70 std::vector<std::string> name = parse_algorithm_name(algo_spec);
71 if(name.size() == 0)
72 return 0;
73 const std::string algo_name = deref_alias(name[0]);
74
75 HANDLE_TYPE_NO_ARGS("AES", AES);
76 HANDLE_TYPE_NO_ARGS("AES-128", AES_128);
77 HANDLE_TYPE_NO_ARGS("AES-192", AES_192);
78 HANDLE_TYPE_NO_ARGS("AES-256", AES_256);
79 HANDLE_TYPE_NO_ARGS("DES", DES);
80 HANDLE_TYPE_NO_ARGS("DESX", DESX);
81 HANDLE_TYPE_NO_ARGS("TripleDES", TripleDES);
82
83 return 0;
84 }
85
86/*************************************************
87* Look for an algorithm with this name *
88*************************************************/
89StreamCipher*
90Default_Engine::find_stream_cipher(const std::string& algo_spec) const
91 {
92 std::vector<std::string> name = parse_algorithm_name(algo_spec);
93 if(name.size() == 0)
94 return 0;
95 const std::string algo_name = deref_alias(name[0]);
96
97 HANDLE_TYPE_ONE_U32BIT("ARC4", ARC4, 0);
98 HANDLE_TYPE_ONE_U32BIT("RC4_drop", ARC4, 768);
99
100
101 return 0;
102 }
103
104/*************************************************
105* Look for an algorithm with this name *
106*************************************************/
107HashFunction*
108Default_Engine::find_hash(const std::string& algo_spec) const
109 {
110 std::vector<std::string> name = parse_algorithm_name(algo_spec);
111 if(name.size() == 0)
112 return 0;
113 const std::string algo_name = deref_alias(name[0]);
114
115 HANDLE_TYPE_NO_ARGS("CRC32", CRC32);
116 HANDLE_TYPE_NO_ARGS("SHA-160", SHA_160);
117 HANDLE_TYPE_NO_ARGS("SHA-256", SHA_256);
118 return 0;
119 }
120
121/*************************************************
122* Look for an algorithm with this name *
123*************************************************/
124MessageAuthenticationCode*
125Default_Engine::find_mac(const std::string& algo_spec) const
126 {
127 std::vector<std::string> name = parse_algorithm_name(algo_spec);
128 if(name.size() == 0)
129 return 0;
130 const std::string algo_name = deref_alias(name[0]);
131
132 HANDLE_TYPE_ONE_STRING("HMAC", HMAC);
133
134 return 0;
135 }
136
137}

Archive Download this file

Branches

Tags

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