monotone

monotone Mtn Source Tree

Root/botan/dl_algo.cpp

1/*************************************************
2* DL Scheme Source File *
3* (C) 1999-2005 The Botan Project *
4*************************************************/
5
6#include <botan/dl_algo.h>
7#include <botan/numthry.h>
8#include <botan/asn1.h>
9
10namespace Botan {
11
12/*************************************************
13* Return the X.509 public key encoding *
14*************************************************/
15MemoryVector<byte> DL_Scheme_PublicKey::DER_encode_pub() const
16 {
17 DER_Encoder encoder;
18 DER::encode(encoder, y);
19 return encoder.get_contents();
20 }
21
22/*************************************************
23* Return the X.509 parameters encoding *
24*************************************************/
25MemoryVector<byte> DL_Scheme_PublicKey::DER_encode_params() const
26 {
27 return group.DER_encode(group_format());
28 }
29
30/*************************************************
31* Decode X.509 public key encoding *
32*************************************************/
33void DL_Scheme_PublicKey::BER_decode_pub(DataSource& source)
34 {
35 BER_Decoder decoder(source);
36 BER::decode(decoder, y);
37 if(y < 2 || y >= group_p())
38 throw Invalid_Argument(algo_name() + ": Invalid public key");
39 X509_load_hook();
40 }
41
42/*************************************************
43* Decode X.509 algorithm parameters *
44*************************************************/
45void DL_Scheme_PublicKey::BER_decode_params(DataSource& source)
46 {
47 group.BER_decode(source, group_format());
48 }
49
50/*************************************************
51* Return the PKCS #8 private key encoding *
52*************************************************/
53SecureVector<byte> DL_Scheme_PrivateKey::DER_encode_priv() const
54 {
55 DER_Encoder encoder;
56 DER::encode(encoder, x);
57 return encoder.get_contents();
58 }
59
60/*************************************************
61* Decode a PKCS #8 private key encoding *
62*************************************************/
63void DL_Scheme_PrivateKey::BER_decode_priv(DataSource& source)
64 {
65 BER_Decoder decoder(source);
66 BER::decode(decoder, x);
67 PKCS8_load_hook();
68 check_loaded_private();
69 }
70
71/*************************************************
72* Check Public DL Parameters *
73*************************************************/
74bool DL_Scheme_PublicKey::check_key(bool strong) const
75 {
76 if(y < 2 || y >= group_p())
77 return false;
78 if(!group.verify_group(strong))
79 return false;
80 return true;
81 }
82
83/*************************************************
84* Check DL Scheme Private Parameters *
85*************************************************/
86bool DL_Scheme_PrivateKey::check_key(bool strong) const
87 {
88 const BigInt& p = group_p();
89 const BigInt& g = group_g();
90
91 if(y < 2 || y >= p || x < 2 || x >= p)
92 return false;
93 if(!group.verify_group(strong))
94 return false;
95
96 if(!strong)
97 return true;
98
99 if(y != power_mod(g, x, p))
100 return false;
101
102 return true;
103 }
104
105}

Archive Download this file

Branches

Tags

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