Botan
1.11.4
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
src
libstate
lookup.cpp
Go to the documentation of this file.
1
/*
2
* Algorithm Retrieval
3
* (C) 1999-2007 Jack Lloyd
4
*
5
* Distributed under the terms of the Botan license
6
*/
7
8
#include <botan/lookup.h>
9
#include <botan/libstate.h>
10
#include <botan/engine.h>
11
12
namespace
Botan {
13
14
/*
15
* Query if an algorithm exists
16
*/
17
bool
have_algorithm
(
const
std::string& name)
18
{
19
Algorithm_Factory
& af =
global_state
().
algorithm_factory
();
20
21
if
(af.
prototype_block_cipher
(name))
22
return
true
;
23
if
(af.
prototype_stream_cipher
(name))
24
return
true
;
25
if
(af.
prototype_hash_function
(name))
26
return
true
;
27
if
(af.
prototype_mac
(name))
28
return
true
;
29
return
false
;
30
}
31
32
/*
33
* Query the block size of a cipher or hash
34
*/
35
size_t
block_size_of
(
const
std::string& name)
36
{
37
Algorithm_Factory
& af =
global_state
().
algorithm_factory
();
38
39
if
(
const
BlockCipher
* cipher = af.
prototype_block_cipher
(name))
40
return
cipher->block_size();
41
42
if
(
const
HashFunction
* hash = af.
prototype_hash_function
(name))
43
return
hash->hash_block_size();
44
45
throw
Algorithm_Not_Found
(name);
46
}
47
48
/*
49
* Query the output_length() of a hash or MAC
50
*/
51
size_t
output_length_of
(
const
std::string& name)
52
{
53
Algorithm_Factory
& af =
global_state
().
algorithm_factory
();
54
55
if
(
const
HashFunction
* hash = af.
prototype_hash_function
(name))
56
return
hash->output_length();
57
58
if
(
const
MessageAuthenticationCode
*
mac
= af.
prototype_mac
(name))
59
return
mac
->
output_length
();
60
61
throw
Algorithm_Not_Found
(name);
62
}
63
64
/*
65
* Get a cipher object
66
*/
67
Keyed_Filter
*
get_cipher
(
const
std::string& algo_spec,
68
Cipher_Dir
direction)
69
{
70
Algorithm_Factory
& af =
global_state
().
algorithm_factory
();
71
72
Algorithm_Factory::Engine_Iterator
i(af);
73
74
while
(
Engine
* engine = i.
next
())
75
{
76
if
(
Keyed_Filter
* algo = engine->get_cipher(algo_spec, direction, af))
77
return
algo;
78
}
79
80
throw
Algorithm_Not_Found
(algo_spec);
81
}
82
83
/*
84
* Get a cipher object
85
*/
86
Keyed_Filter
*
get_cipher
(
const
std::string& algo_spec,
87
const
SymmetricKey
& key,
88
const
InitializationVector
& iv,
89
Cipher_Dir
direction)
90
{
91
Keyed_Filter
* cipher =
get_cipher
(algo_spec, direction);
92
cipher->
set_key
(key);
93
94
if
(iv.
length
())
95
cipher->
set_iv
(iv);
96
97
return
cipher;
98
}
99
100
/*
101
* Get a cipher object
102
*/
103
Keyed_Filter
*
get_cipher
(
const
std::string& algo_spec,
104
const
SymmetricKey
& key,
105
Cipher_Dir
direction)
106
{
107
return
get_cipher
(algo_spec,
108
key,
InitializationVector
(), direction);
109
}
110
111
}
Generated on Wed May 1 2013 08:42:15 for Botan by
1.8.3.1