1 /* $OpenBSD: sm4.h,v 1.1 2019/03/17 17:42:37 tb Exp $ */ 2 /* 3 * Copyright (c) 2017, 2019 Ribose Inc 4 * 5 * Permission to use, copy, modify, and/or distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18 #ifndef HEADER_SM4_H 19 #define HEADER_SM4_H 20 21 #include <stdint.h> 22 23 #include <openssl/opensslconf.h> 24 25 #ifdef __cplusplus 26 extern "C" { 27 #endif 28 29 #ifdef OPENSSL_NO_SM4 30 #error SM4 is disabled. 31 #endif 32 33 #define SM4_DECRYPT 0 34 #define SM4_ENCRYPT 1 35 36 #define SM4_BLOCK_SIZE 16 37 #define SM4_KEY_SCHEDULE 32 38 39 typedef struct sm4_key_st { 40 unsigned char opaque[128]; 41 } SM4_KEY; 42 43 int SM4_set_key(const uint8_t *key, SM4_KEY *ks); 44 void SM4_decrypt(const uint8_t *in, uint8_t *out, const SM4_KEY *ks); 45 void SM4_encrypt(const uint8_t *in, uint8_t *out, const SM4_KEY *ks); 46 47 #ifdef __cplusplus 48 } 49 #endif 50 51 #endif /* HEADER_SM4_H */ 52