Digital Authentication Framework 6.0.1.33
Public Member Functions | Static Public Member Functions | Protected Types | Protected Attributes

DAMessage Class Reference

Encapsulates a message and various (optional) crypto parameters. More...

#include <DigitalAuthenticationFramework.h>

List of all members.

Public Member Functions

 DAMessage ()
 Constructor Creates an empty message with all zero-length entries.
bool getMechanism (DAMechanism &mech) const
 Return cryptographic mechanism identifier.
bool getIV (DAData &iv) const
 Return IV.
bool getPlaintext (DAData &data) const
 Get the original plaintext/signed message.
bool getCiphertext (DAData &data) const
 Get the final encrypted message or signature.
DADigestType getDigestType () const
 Gets digest (hash) type used for signature.
void setMechanism (const DAMechanism &mech)
 Set Crypto Algorithm.
bool setMechanismForRSAPkcs1Signature ()
 Set mechanism appropriately for RSA-SSA-PKCS1 signatures.
bool setMechanismForDSA ()
 Set mechanism appropriately for DSA algorithm.
bool setMechanismForECDSA ()
 Set mechanism appropriately for ECDSA algorithm.
void setIV (const DAData &iv)
 Set IV.
void setPlaintext (const DAData &data)
 Set plaintext buffer.
void setCiphertext (const DAData &data)
 Set ciphertext buffer.
void setDigestType (DADigestType dtype)
 Set digest type.
void unsetMechanism ()
 Remove Crypto Algorithm.
void unsetIV ()
 Remove IV.
void unsetPlaintext ()
 Remove plaintext.
void unsetCiphertext ()
 Remove ciphertext.
void unsetDigestType ()
 Unset digestType.
bool applyDefaultDigest ()
 Ensure a DAMessage contains a message hash for signature.
bool getPkcs1SignatureData (DAData &msg)
 Create a byte string suitable for RSA PKCS#1 signature.

Static Public Member Functions

static DADigestType getDigestFromMech (const DAMechanism &mech)
 Get hash type associated with a mechanism.

Protected Types

enum  { HAVE_PLAINTEXT = 1, HAVE_CIPHERTEXT = 2, HAVE_IV = 4, HAVE_MECH = 8 }

Protected Attributes

DAData m_plaintext
 Plaintext bytes.
DAData m_ciphertext
 Ciphertext bytes.
DAData m_iv
 IV bytes.
DAMechanism m_mech
 Mechanism (OID)
unsigned m_flags
 Flags (HAVE_PLAINTEXT etc)
DADigestType m_digestType
 Digest used for signed message.

Detailed Description

Encapsulates a message and various (optional) crypto parameters.

Keys operate on Messages.


Member Enumeration Documentation

anonymous enum [protected]
Enumerator:
HAVE_PLAINTEXT 

m_plaintext has been set

HAVE_CIPHERTEXT 

m_ciphertext has been set

HAVE_IV 

m_iv has been set

HAVE_MECH 

m_mech has been set


Member Function Documentation

bool DAMessage::applyDefaultDigest ( )

Ensure a DAMessage contains a message hash for signature.

If the digest type (see getDigestType()) is not DA_DIGEST_NONE, leaves the message unchanged, and returns true.

Otherwise, if the mechanism (see getMechanism()) has already been set, applies the hash algorithm appropriate to that mechanism. The message's plaintext field is replaced by the hash, and the digest type is set accordingly. This method will return true if the operation succeeded, and false if the mechanism was not recognised.

If the mechanism was not set, a default hash algorithm is chosen (in this release, SHA-256). The plaintext is replaced by its hash, and the digest type field is set (to DA_DIGEST_SHA256). The method then returns true.

Returns:
true if operation succeeded, false if the mechanism was set on entry but not for a supported hash type.
static DADigestType DAMessage::getDigestFromMech ( const DAMechanism mech) [static]

Get hash type associated with a mechanism.

Parameters:
mechSpecifier for an (asymmetric) signature mechanism
Returns:
Digest type associated with this mechanism, or DA_DIGEST_NONE if it's unrecognised.
DADigestType DAMessage::getDigestType ( ) const [inline]

Gets digest (hash) type used for signature.

Returns:
DA_DIGEST_NONE if message is not hashed
bool DAMessage::getMechanism ( DAMechanism mech) const [inline]

Return cryptographic mechanism identifier.

This is, in most cases, a value chosen from class CommonMech. It is set by the DAKey::sign() and DAKey::encrypt() methods, and must be set by the called before DAKey::verify() and DAKey::decrypt().

Returns:
true if a mechanism was set (and mech had a value assigned). Returns false if no mechanism is set.
bool DAMessage::getPkcs1SignatureData ( DAData msg)

Create a byte string suitable for RSA PKCS#1 signature.

Parameters:
msgByte-block returned. This is the DER encoding of a SEQUENCE containing the OID of the hash function followed by the hash value. See e.g. RFC 3447 section 9.2. This function will also apply a default hash function if the message doesn't have a digest type set.
Returns:
true if operation succeeded, false if the DAMessage is invalid/unsuitable.
bool DAMessage::setMechanismForDSA ( )

Set mechanism appropriately for DSA algorithm.

Chooses a suitable DAMechanism (see common_mechs.h) for the hash algorithm identified by the m_digestType field, and sets it as the m_mech field.

Returns:
false if invalid mechanism in m_digestType.
bool DAMessage::setMechanismForECDSA ( )

Set mechanism appropriately for ECDSA algorithm.

Chooses a suitable DAMechanism (see common_mechs.h) for the hash algorithm identified by the m_digestType field, and sets it as the m_mech field.

Returns:
false if invalid mechanism in m_digestType.
bool DAMessage::setMechanismForRSAPkcs1Signature ( )

Set mechanism appropriately for RSA-SSA-PKCS1 signatures.

Chooses a suitable DAMechanism (see common_mechs.h) for the hash algorithm identified by the m_digestType field, and sets it as the m_mech field.

Returns:
false if invalid mechanism in m_digestType.

The documentation for this class was generated from the following file: