1*e7be843bSPierre Pronchery /* 2*e7be843bSPierre Pronchery * Copyright 2022-2023 The OpenSSL Project Authors. All Rights Reserved. 3*e7be843bSPierre Pronchery * 4*e7be843bSPierre Pronchery * Licensed under the Apache License 2.0 (the "License"). You may not use 5*e7be843bSPierre Pronchery * this file except in compliance with the License. You can obtain a copy 6*e7be843bSPierre Pronchery * in the file LICENSE in the source distribution or at 7*e7be843bSPierre Pronchery * https://www.openssl.org/source/license.html 8*e7be843bSPierre Pronchery */ 9*e7be843bSPierre Pronchery 10*e7be843bSPierre Pronchery #include <crypto/sm4.h> 11*e7be843bSPierre Pronchery #include "prov/ciphercommon.h" 12*e7be843bSPierre Pronchery #include "crypto/sm4_platform.h" 13*e7be843bSPierre Pronchery 14*e7be843bSPierre Pronchery PROV_CIPHER_FUNC(void, xts_stream, 15*e7be843bSPierre Pronchery (const unsigned char *in, unsigned char *out, size_t len, 16*e7be843bSPierre Pronchery const SM4_KEY *key1, const SM4_KEY *key2, 17*e7be843bSPierre Pronchery const unsigned char iv[16], const int enc)); 18*e7be843bSPierre Pronchery 19*e7be843bSPierre Pronchery typedef struct prov_sm4_xts_ctx_st { 20*e7be843bSPierre Pronchery /* Must be first */ 21*e7be843bSPierre Pronchery PROV_CIPHER_CTX base; 22*e7be843bSPierre Pronchery 23*e7be843bSPierre Pronchery /* SM4 key schedules to use */ 24*e7be843bSPierre Pronchery union { 25*e7be843bSPierre Pronchery OSSL_UNION_ALIGN; 26*e7be843bSPierre Pronchery SM4_KEY ks; 27*e7be843bSPierre Pronchery } ks1, ks2; 28*e7be843bSPierre Pronchery 29*e7be843bSPierre Pronchery /*- 30*e7be843bSPierre Pronchery * XTS standard to use with SM4-XTS algorithm 31*e7be843bSPierre Pronchery * 32*e7be843bSPierre Pronchery * Must be 0 or 1, 33*e7be843bSPierre Pronchery * 0 for XTS mode specified by GB/T 17964-2021 34*e7be843bSPierre Pronchery * 1 for XTS mode specified by IEEE Std 1619-2007 35*e7be843bSPierre Pronchery */ 36*e7be843bSPierre Pronchery int xts_standard; 37*e7be843bSPierre Pronchery 38*e7be843bSPierre Pronchery XTS128_CONTEXT xts; 39*e7be843bSPierre Pronchery 40*e7be843bSPierre Pronchery /* Stream function for XTS mode specified by GB/T 17964-2021 */ 41*e7be843bSPierre Pronchery OSSL_xts_stream_fn stream_gb; 42*e7be843bSPierre Pronchery /* Stream function for XTS mode specified by IEEE Std 1619-2007 */ 43*e7be843bSPierre Pronchery OSSL_xts_stream_fn stream; 44*e7be843bSPierre Pronchery } PROV_SM4_XTS_CTX; 45*e7be843bSPierre Pronchery 46*e7be843bSPierre Pronchery const PROV_CIPHER_HW *ossl_prov_cipher_hw_sm4_xts(size_t keybits); 47