dsa.cpp
// dsa.cpp - originally written and placed in the public domain by Wei Dai
#include "pch.h"
#ifndef CRYPTOPP_IMPORTS
#include "dsa.h"
#include "asn.h"
#include "integer.h"
#include "filters.h"
#include "nbtheory.h"
NAMESPACE_BEGIN(CryptoPP)
size_t DSAConvertSignatureFormat(byte *buffer, size_t bufferSize, DSASignatureFormat toFormat, const byte *signature, size_t signatureLen, DSASignatureFormat fromFormat)
{
Integer r, s;
StringStore store(signature, signatureLen);
ArraySink sink(buffer, bufferSize);
switch (fromFormat)
{
case DSA_P1363:
r.Decode(store, signatureLen/2);
s.Decode(store, signatureLen/2);
break;
case DSA_DER:
{
BERSequenceDecoder seq(store);
r.BERDecode(seq);
s.BERDecode(seq);
seq.MessageEnd();
break;
}
case DSA_OPENPGP:
r.OpenPGPDecode(store);
s.OpenPGPDecode(store);
break;
}
switch (toFormat)
{
case DSA_P1363:
r.Encode(sink, bufferSize/2);
s.Encode(sink, bufferSize/2);
break;
case DSA_DER:
{
DERSequenceEncoder seq(sink);
r.DEREncode(seq);
s.DEREncode(seq);
seq.MessageEnd();
break;
}
case DSA_OPENPGP:
r.OpenPGPEncode(sink);
s.OpenPGPEncode(sink);
break;
}
return (size_t)sink.TotalPutLength();
}
NAMESPACE_END
#endif
asn.h
Classes and functions for working with ANS.1 objects.
ArraySink
Copy input to a memory buffer.
Definition: filters.h:1200
BERSequenceDecoder
BER Sequence Decoder.
Definition: asn.h:525
DERSequenceEncoder
DER Sequence Encoder.
Definition: asn.h:557
Integer
Multiple precision integer with arithmetic operations.
Definition: integer.h:50
Integer::DEREncode
void DEREncode(BufferedTransformation &bt) const
Encode in DER format.
Integer::OpenPGPDecode
void OpenPGPDecode(const byte *input, size_t inputLen)
Decode from OpenPGP format.
Integer::BERDecode
void BERDecode(const byte *input, size_t inputLen)
Decode from BER format.
Integer::OpenPGPEncode
size_t OpenPGPEncode(byte *output, size_t bufferSize) const
Encode absolute value in OpenPGP format.
Integer::Decode
void Decode(const byte *input, size_t inputLen, Signedness sign=UNSIGNED)
Decode from big-endian byte array.
Integer::Encode
void Encode(byte *output, size_t outputLen, Signedness sign=UNSIGNED) const
Encode in big-endian format.
StringStore
String-based implementation of Store interface.
Definition: filters.h:1259
dsa.h
Classes for the DSA signature algorithm.
DSAConvertSignatureFormat
size_t DSAConvertSignatureFormat(byte *buffer, size_t bufferSize, DSASignatureFormat toFormat, const byte *signature, size_t signatureLen, DSASignatureFormat fromFormat)
Converts between signature encoding formats.
DSASignatureFormat
DSASignatureFormat
DSA Signature Format.
Definition: dsa.h:20
DSA_OPENPGP
@ DSA_OPENPGP
OpenPGP signature encoding format.
Definition: dsa.h:26
DSA_P1363
@ DSA_P1363
Crypto++ native signature encoding format.
Definition: dsa.h:22
DSA_DER
@ DSA_DER
signature encoding format used by OpenSSL, Java and .Net
Definition: dsa.h:24
filters.h
Implementation of BufferedTransformation's attachment interface.
integer.h
Multiple precision integer with arithmetic operations.
CryptoPP
Crypto++ library namespace.
nbtheory.h
Classes and functions for number theoretic operations.
pch.h
Precompiled header file.