monotone

monotone Mtn Source Tree

Root/botan/get_enc.cpp

1/*************************************************
2* EMSA/EME/KDF/MGF Retrieval Source File *
3* (C) 1999-2005 The Botan Project *
4*************************************************/
5
6#include <botan/lookup.h>
7#include <botan/parsing.h>
8#include <botan/emsa.h>
9#include <botan/eme.h>
10#include <botan/kdf.h>
11#include <botan/mgf1.h>
12#include <botan/util.h>
13
14namespace Botan {
15
16/*************************************************
17* Get an EMSA by name *
18*************************************************/
19EMSA* get_emsa(const std::string& algo_spec)
20 {
21 std::vector<std::string> name = parse_algorithm_name(algo_spec);
22 const std::string emsa_name = deref_alias(name[0]);
23
24 if(emsa_name == "Raw")
25 {
26 if(name.size() == 1)
27 return new EMSA_Raw;
28 }
29 else if(emsa_name == "EMSA1")
30 {
31 if(name.size() == 2)
32 return new EMSA1(name[1]);
33 }
34 else if(emsa_name == "EMSA2")
35 {
36 if(name.size() == 2)
37 return new EMSA2(name[1]);
38 }
39 else if(emsa_name == "EMSA3")
40 {
41 if(name.size() == 2)
42 return new EMSA3(name[1]);
43 }
44 else if(emsa_name == "EMSA4")
45 {
46 if(name.size() == 2)
47 return new EMSA4(name[1], "MGF1");
48 if(name.size() == 3)
49 return new EMSA4(name[1], name[2]);
50 if(name.size() == 4)
51 return new EMSA4(name[1], name[2], to_u32bit(name[3]));
52 }
53 else
54 throw Algorithm_Not_Found(algo_spec);
55
56 throw Invalid_Algorithm_Name(algo_spec);
57 }
58
59/*************************************************
60* Get an EME by name *
61*************************************************/
62EME* get_eme(const std::string& algo_spec)
63 {
64 std::vector<std::string> name = parse_algorithm_name(algo_spec);
65 const std::string eme_name = deref_alias(name[0]);
66
67 if(eme_name == "PKCS1v15")
68 {
69 if(name.size() == 1)
70 return new EME_PKCS1v15;
71 }
72 else if(eme_name == "EME1")
73 {
74 if(name.size() == 2)
75 return new EME1(name[1], "MGF1");
76 if(name.size() == 3)
77 return new EME1(name[1], name[2]);
78 }
79 else
80 throw Algorithm_Not_Found(algo_spec);
81
82 throw Invalid_Algorithm_Name(algo_spec);
83 }
84
85/*************************************************
86* Get an KDF by name *
87*************************************************/
88KDF* get_kdf(const std::string& algo_spec)
89 {
90 std::vector<std::string> name = parse_algorithm_name(algo_spec);
91 const std::string kdf_name = deref_alias(name[0]);
92
93 if(kdf_name == "KDF1")
94 {
95 if(name.size() == 2)
96 return new KDF1(name[1]);
97 }
98 else if(kdf_name == "KDF2")
99 {
100 if(name.size() == 2)
101 return new KDF2(name[1]);
102 }
103 else if(kdf_name == "X9.42-PRF")
104 {
105 if(name.size() == 2)
106 return new X942_PRF(name[1]);
107 }
108 else
109 throw Algorithm_Not_Found(algo_spec);
110
111 throw Invalid_Algorithm_Name(algo_spec);
112 }
113
114/*************************************************
115* Get a MGF by name *
116*************************************************/
117MGF* get_mgf(const std::string& algo_spec)
118 {
119 std::vector<std::string> name = parse_algorithm_name(algo_spec);
120 const std::string mgf_name = deref_alias(name[0]);
121
122 if(mgf_name == "MGF1")
123 {
124 if(name.size() == 2)
125 return new MGF1(name[1]);
126 }
127 else
128 throw Algorithm_Not_Found(algo_spec);
129
130 throw Invalid_Algorithm_Name(algo_spec);
131 }
132
133}

Archive Download this file

Branches

Tags

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