Crypto++ 8.2 Free C++ class library of cryptographic schemes

dsa.cpp
1 // dsa.cpp - originally written and placed in the public domain by Wei Dai
2
3 #include "pch.h"
4
5 #ifndef CRYPTOPP_IMPORTS
6
7 #include "dsa.h"
8 #include "asn.h"
9 #include "integer.h"
10 #include "filters.h"
11 #include "nbtheory.h"
12
13 NAMESPACE_BEGIN(CryptoPP)
14
15 size_t DSAConvertSignatureFormat(byte *buffer, size_t bufferSize, DSASignatureFormat toFormat, const byte *signature, size_t signatureLen, DSASignatureFormat fromFormat)
16 {
17 Integer r, s;
18 StringStore store(signature, signatureLen);
19 ArraySink sink(buffer, bufferSize);
20
21 switch (fromFormat)
22 {
23 case DSA_P1363:
24 r.Decode(store, signatureLen/2);
25 s.Decode(store, signatureLen/2);
26 break;
27 case DSA_DER:
28 {
29 BERSequenceDecoder seq(store);
30 r.BERDecode(seq);
31 s.BERDecode(seq);
32 seq.MessageEnd();
33 break;
34 }
35 case DSA_OPENPGP:
36 r.OpenPGPDecode(store);
37 s.OpenPGPDecode(store);
38 break;
39 }
40
41 switch (toFormat)
42 {
43 case DSA_P1363:
44 r.Encode(sink, bufferSize/2);
45 s.Encode(sink, bufferSize/2);
46 break;
47 case DSA_DER:
48 {
49 DERSequenceEncoder seq(sink);
50 r.DEREncode(seq);
51 s.DEREncode(seq);
52 seq.MessageEnd();
53 break;
54 }
55 case DSA_OPENPGP:
56 r.OpenPGPEncode(sink);
57 s.OpenPGPEncode(sink);
58 break;
59 }
60
61 return (size_t)sink.TotalPutLength();
62 }
63
64 NAMESPACE_END
65
66 #endif
DSAConvertSignatureFormat
size_t DSAConvertSignatureFormat(byte *buffer, size_t bufferSize, DSASignatureFormat toFormat, const byte *signature, size_t signatureLen, DSASignatureFormat fromFormat)
Converts between signature encoding formats.
Definition: dsa.cpp:15
Integer::DEREncode
void DEREncode(BufferedTransformation &bt) const
Encode in DER format.
Definition: integer.cpp:3433
DERGeneralEncoder::MessageEnd
void MessageEnd()
Signals the end of messages to the object.
Definition: asn.cpp:624
DSASignatureFormat
DSASignatureFormat
DSA Signature Format.
Definition: dsa.h:20
DSA_P1363
Crypto++ native signature encoding format.
Definition: dsa.h:22
Integer::OpenPGPDecode
void OpenPGPDecode(const byte *input, size_t inputLen)
Decode from OpenPGP format.
Definition: integer.cpp:3489
BERSequenceDecoder
BER Sequence Decoder.
Definition: asn.h:524
ArraySink
Copy input to a memory buffer.
Definition: filters.h:1199
DSA_DER
signature encoding format used by OpenSSL, Java and .Net
Definition: dsa.h:24
Integer
Multiple precision integer with arithmetic operations.
Definition: integer.h:49
pch.h
Precompiled header file.
Integer::OpenPGPEncode
size_t OpenPGPEncode(byte *output, size_t bufferSize) const
Encode absolute value in OpenPGP format.
Definition: integer.cpp:3472
dsa.h
Classes for the DSA signature algorithm.
StringStore
String-based implementation of Store interface.
Definition: filters.h:1258
asn.h
Classes and functions for working with ANS.1 objects.
filters.h
Implementation of BufferedTransformation&#39;s attachment interface.
BERGeneralDecoder::MessageEnd
void MessageEnd()
Signals the end of messages to the object.
Definition: asn.cpp:553
nbtheory.h
Classes and functions for number theoretic operations.
DERSequenceEncoder
DER Sequence Encoder.
Definition: asn.h:556
Integer::Encode
void Encode(byte *output, size_t outputLen, Signedness sign=UNSIGNED) const
Encode in big-endian format.
Definition: integer.cpp:3411
Integer::Decode
void Decode(const byte *input, size_t inputLen, Signedness sign=UNSIGNED)
Decode from big-endian byte array.
Definition: integer.cpp:3357
integer.h
Multiple precision integer with arithmetic operations.
Integer::BERDecode
void BERDecode(const byte *input, size_t inputLen)
Decode from BER format.
Definition: integer.cpp:3440
CryptoPP
Crypto++ library namespace.
DSA_OPENPGP
OpenPGP signature encoding format.
Definition: dsa.h:26
ArraySink::TotalPutLength
lword TotalPutLength()
Provides the number of bytes written to the Sink.
Definition: filters.h:1222