| 1 |
/* |
| 2 |
* Copyright (c) 2025 Björn Esser <besser82 at fedoraproject.org> |
| 3 |
* All rights reserved. |
| 4 |
* |
| 5 |
* Permission to use, copy, modify, and/or distribute this software for any |
| 6 |
* purpose with or without fee is hereby granted. |
| 7 |
* |
| 8 |
* THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 |
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 |
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 11 |
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 |
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 13 |
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 14 |
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 |
*/ |
| 16 |
|
| 17 |
#ifndef _CRYPT_ALG_SM3_H |
| 18 |
#define _CRYPT_ALG_SM3_H |
| 19 |
|
| 20 |
#include "crypt-port.h" |
| 21 |
|
| 22 |
#include <stdint.h> |
| 23 |
|
| 24 |
/* Context structure for SM3 operations. */ |
| 25 |
typedef struct |
| 26 |
{ |
| 27 |
uint32_t state[8]; |
| 28 |
uint64_t count; |
| 29 |
uint8_t buf[64]; |
| 30 |
} sm3_ctx; |
| 31 |
|
| 32 |
/** |
| 33 |
* sm3_init(ctx): |
| 34 |
* Initialize the SM3 context ${ctx}. |
| 35 |
*/ |
| 36 |
extern void sm3_init(sm3_ctx *); |
| 37 |
|
| 38 |
/** |
| 39 |
* sm3_update(ctx, in, len): |
| 40 |
* Input ${len} bytes from ${in} into the SM3 context ${ctx}. |
| 41 |
*/ |
| 42 |
extern void sm3_update(sm3_ctx *, const void *, size_t); |
| 43 |
|
| 44 |
/** |
| 45 |
* sm3_final(digest, ctx): |
| 46 |
* Output the SM3 hash of the data input to the context ${ctx} into the |
| 47 |
* buffer ${digest}. |
| 48 |
*/ |
| 49 |
extern void sm3_final(uint8_t[32], sm3_ctx *); |
| 50 |
|
| 51 |
/** |
| 52 |
* sm3_hash(in, len, digest, ctx): |
| 53 |
* Compute the SM3 hash of ${len} bytes from ${in} and write it to ${digest}, |
| 54 |
* using the prepared context ${ctx}. |
| 55 |
*/ |
| 56 |
extern void sm3_hash(const void *, size_t, uint8_t[32], sm3_ctx *); |
| 57 |
|
| 58 |
/** |
| 59 |
* sm3_buf(in, len, digest): |
| 60 |
* Compute the SM3 hash of ${len} bytes from ${in} and write it to ${digest}. |
| 61 |
*/ |
| 62 |
extern void sm3_buf(const void *, size_t, uint8_t[32]); |
| 63 |
#endif /* _CRYPT_ALG_SM3_H */ |