DEFINITION MODULE Signatures;

        (********************************************************)
        (*                                                      *)
        (*                 Signing a DKIM header                *)
        (*                                                      *)
        (*  Programmer:         P. Moylan                       *)
        (*  Started:            8 August 2023                   *)
        (*  Last edited:        23 March 2024                   *)
        (*  Status:             OK                              *)
        (*                                                      *)
        (*  This is an adaptation of the PublicKeys module in   *)
        (*  my SSH implementation, retaining only those         *)
        (*  features needed for DKIM calculations.              *)
        (*                                                      *)
        (********************************************************)


FROM SYSTEM     IMPORT CARD8;
FROM RSAKeys    IMPORT RSAKeyType;
FROM VarStrings IMPORT ByteStr;
FROM TransLog   IMPORT TransactionLogID;


TYPE PKAType = (rsa_sha2_256, rsa_sha2_512, sshrsa, none);


PROCEDURE Sign (ka: PKAType;  VAR (*IN*) digest: ARRAY OF CARD8;
                                privatekey: RSAKeyType): ByteStr;

    (* Creates a signature using our own private key.  *)

PROCEDURE SignatureValid (ka: PKAType;  digest: ARRAY OF CARD8;
                            publickey: RSAKeyType;
                            VAR (*INOUT*) signature: ByteStr;
                              logID: TransactionLogID): BOOLEAN;

    (* Checks that signature is a valid signature for digest.   *)
    (* During processing the signature is discarded.            *)

END Signatures.

