root/maint/gnulib/lib/sm3.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


   1 /* Declarations of functions and data types used for SM3 sum library
   2    function.
   3    Copyright (C) 2017-2021 Free Software Foundation, Inc.
   4 
   5    This file is free software: you can redistribute it and/or modify
   6    it under the terms of the GNU Lesser General Public License as
   7    published by the Free Software Foundation; either version 2.1 of the
   8    License, or (at your option) any later version.
   9 
  10    This file is distributed in the hope that it will be useful,
  11    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13    GNU Lesser General Public License for more details.
  14 
  15    You should have received a copy of the GNU Lesser General Public License
  16    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
  17 
  18 /* This module can be used to compute SM3 message digest of files or
  19    memory blocks according to the specification GM/T 004-2012
  20    Cryptographic Hash Algorithm SM3, published by State Cryptography
  21    Administration, China.
  22 
  23    The official SM3 cryptographic hash algorithm specification is
  24    available at
  25    <http://www.sca.gov.cn/sca/xwdt/2010-12/17/content_1002389.shtml>. */
  26 
  27 #ifndef SM3_H
  28 # define SM3_H 1
  29 
  30 # include <stdio.h>
  31 # include <stdint.h>
  32 
  33 # if HAVE_OPENSSL_SM3
  34 #  include <openssl/sm3.h>
  35 # endif
  36 
  37 # ifdef __cplusplus
  38 extern "C" {
  39 # endif
  40 
  41 enum { SM3_DIGEST_SIZE = 256 / 8 };
  42 
  43 # if HAVE_OPENSSL_SM3
  44 #  define GL_OPENSSL_NAME 3
  45 #  include "gl_openssl.h"
  46 # else
  47 /* Structure to save state of computation between the single steps.  */
  48 struct sm3_ctx
  49 {
  50   uint32_t state[8];
  51 
  52   uint32_t total[2];
  53   size_t buflen;       /* ≥ 0, ≤ 128 */
  54   uint32_t buffer[32]; /* 128 bytes; the first buflen bytes are in use */
  55 };
  56 
  57 /* Initialize structure containing state of computation. */
  58 extern void sm3_init_ctx (struct sm3_ctx *ctx);
  59 
  60 /* Starting with the result of former calls of this function (or the
  61    initialization function update the context for the next LEN bytes
  62    starting at BUFFER.
  63    It is necessary that LEN is a multiple of 64!!! */
  64 extern void sm3_process_block (const void *buffer, size_t len,
  65                                struct sm3_ctx *ctx);
  66 
  67 /* Starting with the result of former calls of this function (or the
  68    initialization function update the context for the next LEN bytes
  69    starting at BUFFER.
  70    It is NOT required that LEN is a multiple of 64.  */
  71 extern void sm3_process_bytes (const void *buffer, size_t len,
  72                                struct sm3_ctx *ctx);
  73 
  74 /* Process the remaining bytes in the buffer and put result from CTX
  75    in first 32 bytes following RESBUF.  The result is always in little
  76    endian byte order, so that a byte-wise output yields to the wanted
  77    ASCII representation of the message digest.  */
  78 extern void *sm3_finish_ctx (struct sm3_ctx *ctx, void *restrict resbuf);
  79 
  80 /* Put result from CTX in first 32 bytes following RESBUF.  The result is
  81    always in little endian byte order, so that a byte-wise output yields
  82    to the wanted ASCII representation of the message digest.  */
  83 extern void *sm3_read_ctx (const struct sm3_ctx *ctx, void *restrict resbuf);
  84 
  85 /* Compute SM3 message digest for LEN bytes beginning at BUFFER.  The
  86    result is always in little endian byte order, so that a byte-wise
  87    output yields to the wanted ASCII representation of the message
  88    digest.  */
  89 extern void *sm3_buffer (const char *buffer, size_t len,
  90                          void *restrict resblock);
  91 
  92 # endif
  93 
  94 /* Compute SM3 message digest for bytes read from STREAM.  The
  95    resulting message digest number will be written into the 32 bytes
  96    beginning at RESBLOCK.  */
  97 extern int sm3_stream (FILE *stream, void *resblock);
  98 
  99 
 100 # ifdef __cplusplus
 101 }
 102 # endif
 103 
 104 #endif
 105 
 106 /*
 107  * Hey Emacs!
 108  * Local Variables:
 109  * coding: utf-8
 110  * End:
 111  */

/* [previous][next][first][last][top][bottom][index][help] */