uchar C++ tests: Fix build error on FreeBSD 12.
[gnulib.git] / lib / sm3.h
blobfd7cc981d67c71c47bdda0b701fcfb3a11fc3ae3
1 /* Declarations of functions and data types used for SM3 sum library
2 function.
3 Copyright (C) 2017-2020 Free Software Foundation, Inc.
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program 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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
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.
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>. */
27 #ifndef SM3_H
28 # define SM3_H 1
30 # include <stdio.h>
31 # include <stdint.h>
33 # if HAVE_OPENSSL_SM3
34 # include <openssl/sm3.h>
35 # endif
37 # ifdef __cplusplus
38 extern "C" {
39 # endif
41 enum { SM3_DIGEST_SIZE = 256 / 8 };
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
50 uint32_t state[8];
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 */
57 /* Initialize structure containing state of computation. */
58 extern void sm3_init_ctx (struct sm3_ctx *ctx);
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);
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);
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);
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);
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);
92 # endif
93 /* Compute SM3 message digest for bytes read from STREAM. The
94 resulting message digest number will be written into the 32 bytes
95 beginning at RESBLOCK. */
96 extern int sm3_stream (FILE *stream, void *resblock);
99 # ifdef __cplusplus
101 # endif
103 #endif
106 * Hey Emacs!
107 * Local Variables:
108 * coding: utf-8
109 * End: