summaryrefslogtreecommitdiff
path: root/providers/implementations/ciphers/cipher_sm4_xts.h
blob: cfca596979cc81f9929806ddc664598a442a8d8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
 * Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
 *
 * Licensed under the Apache License 2.0 (the "License").  You may not use
 * this file except in compliance with the License.  You can obtain a copy
 * in the file LICENSE in the source distribution or at
 * https://www.openssl.org/source/license.html
 */

#include <crypto/sm4.h>
#include "prov/ciphercommon.h"
#include "crypto/sm4_platform.h"

PROV_CIPHER_FUNC(void, xts_stream,
                 (const unsigned char *in, unsigned char *out, size_t len,
                  const SM4_KEY *key1, const SM4_KEY *key2,
                  const unsigned char iv[16], const int enc));

typedef struct prov_sm4_xts_ctx_st {
    /* Must be first */
    PROV_CIPHER_CTX base;

    /* SM4 key schedules to use */
    union {
        OSSL_UNION_ALIGN;
        SM4_KEY ks;
    } ks1, ks2;

    /*-
     * XTS standard to use with SM4-XTS algorithm
     *
     * Must be 0 or 1,
     * 0 for XTS mode specified by GB/T 17964-2021
     * 1 for XTS mode specified by IEEE Std 1619-2007
     */
    int xts_standard;

    XTS128_CONTEXT xts;

    /* Stream function for XTS mode specified by GB/T 17964-2021 */
    OSSL_xts_stream_fn stream_gb;
    /* Stream function for XTS mode specified by IEEE Std 1619-2007 */
    OSSL_xts_stream_fn stream;
} PROV_SM4_XTS_CTX;

const PROV_CIPHER_HW *ossl_prov_cipher_hw_sm4_xts(size_t keybits);