semf
semf::app::SignaturePkcs1 Class Referenceabstract

Class for using PKCS1 (Public-Key Cryptography Standards Version 1) asymmetric encryption/decryption for signing and verification. More...

#include <signaturepkcs1.h>

Collaboration diagram for semf::app::SignaturePkcs1:
Collaboration graph

Public Types

enum  State : bool { Ok = true , Error = false }
 
enum  HashAlgorithm { Sha256 , Md5 }
 

Public Member Functions

virtual ~SignaturePkcs1 ()=default
 
virtual State setPublicKey (const uint8_t n[], size_t nLen, const uint8_t e[], size_t eLen)=0
 Pass the modulus N and public key E to the class. More...
 
virtual State setPrivateKey (const uint8_t n[], size_t nLen, const uint8_t d[], size_t dLen)=0
 Pass the modulus N and private key D to the class. More...
 
virtual State sign (const uint8_t hashDigest[], size_t hashBitLen, uint8_t sign[], HashAlgorithm hashAlgorithm)=0
 The function executes a hash algorithm on the given data, and signs the hash-digest using the private key. More...
 
virtual State verify (const uint8_t hashDigest[], size_t hashBitLen, const uint8_t sign[], HashAlgorithm hashAlgorithm)=0
 The function executes a verification of the data data with the given signature sign. More...
 

Detailed Description

Class for using PKCS1 (Public-Key Cryptography Standards Version 1) asymmetric encryption/decryption for signing and verification.

Note
The format of the keys (public and private), modular and the data is big endian, where the MSByte is places at the byte with the minimum address.
The size of the public key E and private key D must be less the modulus N.

Definition at line 26 of file signaturepkcs1.h.

Member Enumeration Documentation

◆ HashAlgorithm

Enum for the used hash algorithm

Enumerator
Sha256 
Md5 

Definition at line 36 of file signaturepkcs1.h.

◆ State

Enum for the output state of the function.

Enumerator
Ok 
Error 

Definition at line 30 of file signaturepkcs1.h.

Constructor & Destructor Documentation

◆ ~SignaturePkcs1()

virtual semf::app::SignaturePkcs1::~SignaturePkcs1 ( )
virtualdefault

Member Function Documentation

◆ setPrivateKey()

virtual State semf::app::SignaturePkcs1::setPrivateKey ( const uint8_t  n[],
size_t  nLen,
const uint8_t  d[],
size_t  dLen 
)
pure virtual

Pass the modulus N and private key D to the class.

The size of the message m must fulfill 0 <= m < n.

Parameters
nPointer to the address of the modulus (in binary form).
nLenSize of the modulus in bytes.
dPointer to the address of the private key (in binary form).
dLenSize of the private key in bytes.
Returns
STATE::OK on success and STATE::FAILED on failure.

◆ setPublicKey()

virtual State semf::app::SignaturePkcs1::setPublicKey ( const uint8_t  n[],
size_t  nLen,
const uint8_t  e[],
size_t  eLen 
)
pure virtual

Pass the modulus N and public key E to the class.

The size of the message m must fulfill 0 <= m < n.

Parameters
nPointer to the address of the modulus (in binary form).
nLenSize of the modulus in bytes.
ePointer to the address of the public key (in binary form).
eLenSize of the public key in bytes.
Returns
STATE::OK on success and STATE::FAILED on failure.

◆ sign()

virtual State semf::app::SignaturePkcs1::sign ( const uint8_t  hashDigest[],
size_t  hashBitLen,
uint8_t  sign[],
HashAlgorithm  hashAlgorithm 
)
pure virtual

The function executes a hash algorithm on the given data, and signs the hash-digest using the private key.

Parameters
hashDigestThe hash which should be signed.
hashBitLenThe size of the hash checksum in bits.
signThe signature produced from the function, it has the same size of the modular N.
hashAlgorithmThe hash function which is performed on the input data.
Returns
STATE::OK on success and STATE::FAILED on failure.

◆ verify()

virtual State semf::app::SignaturePkcs1::verify ( const uint8_t  hashDigest[],
size_t  hashBitLen,
const uint8_t  sign[],
HashAlgorithm  hashAlgorithm 
)
pure virtual

The function executes a verification of the data data with the given signature sign.

Parameters
hashDigestThe hash which should be verified.
hashBitLenThe size of the hash checksum in bits.
signThe claimed signature, it is decrypted and compared to the hash-digest of the data.N.
hashAlgorithmThe hash function which is performed on the input data.
Returns
STATE::OK on success and STATE::FAILED on failure.