(**************************************************************************)
(*                                                                        *)
(*  Part of encryption software                                           *)
(*  Copyright (C) 2021   Peter Moylan                                     *)
(*                                                                        *)
(*  This program is free software: you can redistribute it and/or modify  *)
(*  it under the terms of the GNU General Public License as published by  *)
(*  the Free Software Foundation, either version 3 of the License, or     *)
(*  (at your option) any later version.                                   *)
(*                                                                        *)
(*  This program is distributed in the hope that it will be useful,       *)
(*  but WITHOUT ANY WARRANTY; without even the implied warranty of        *)
(*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *)
(*  GNU General Public License for more details.                          *)
(*                                                                        *)
(*  You should have received a copy of the GNU General Public License     *)
(*  along with this program.  If not, see <http://www.gnu.org/licenses/>. *)
(*                                                                        *)
(*  To contact author:   http://www.pmoylan.org   peter@pmoylan.org       *)
(*                                                                        *)
(**************************************************************************)

DEFINITION MODULE Digests;

        (********************************************************)
        (*                                                      *)
        (*  Converting a message digest to a hexidecimal string *)
        (*  for the case where the data are already in          *)
        (*  big-endian form.                                    *)
        (*                                                      *)
        (*  Common code for a variety of digest procedures.     *)
        (*                                                      *)
        (*  Programmer:         P. Moylan                       *)
        (*  Started:            3 May 2021                      *)
        (*  Last edited:        3 May 2021                      *)
        (*  Status:             OK                              *)
        (*                                                      *)
        (********************************************************)


FROM SYSTEM IMPORT CARD8;


PROCEDURE DigestToString (N: CARDINAL;  VAR (*IN*) digest: ARRAY OF CARD8;
                             VAR (*OUT*) result: ARRAY OF CHAR);

    (* Converts the digest to a 2*N-character string.  If there is not enough   *)
    (* space for the result, produces a leading substring of the full result.   *)

    (* The value you need for N is:         *)
    (*     16   for MD5                     *)
    (*     20   for SHA1                    *)
    (*     28   for SHA-224                 *)
    (*     32   for SHA-256                 *)
    (*     48   for SHA-384                 *)
    (*     64   for SHA-512                 *)

END Digests.

