sm4.h File Reference

SM4 encryption algorithm. More...

#include "core/crypto.h"

Go to the source code of this file.

Data Structures

struct  Sm4Context
 SM4 algorithm context. More...
 

Macros

#define SM4_PRIVATE_CONTEXT
 
#define SM4_BLOCK_SIZE   16
 
#define SM4_CIPHER_ALGO   (&sm4CipherAlgo)
 

Functions

error_t sm4Init (Sm4Context *context, const uint8_t *key, size_t keyLen)
 Key expansion. More...
 
void sm4EncryptBlock (Sm4Context *context, const uint8_t *input, uint8_t *output)
 Encrypt a 16-byte block using SM4 algorithm. More...
 
void sm4DecryptBlock (Sm4Context *context, const uint8_t *input, uint8_t *output)
 Decrypt a 16-byte block using SM4 algorithm. More...
 
void sm4Deinit (Sm4Context *context)
 Release SM4 context. More...
 

Variables

const uint8_t SM4_CBC_OID [8]
 
const uint8_t SM4_ECB_OID [8]
 
const uint8_t SM4_OFB_OID [8]
 
const uint8_t SM4_CFB_OID [8]
 
const uint8_t SM4_CTR_OID [8]
 
const uint8_t SM4_GCM_OID [8]
 
const uint8_t SM4_CCM_OID [8]
 
const uint8_t SM4_XTS_OID [8]
 
const CipherAlgo sm4CipherAlgo
 

Detailed Description

SM4 encryption algorithm.

License

SPDX-License-Identifier: GPL-2.0-or-later

Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneCRYPTO Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
2.4.4

Definition in file sm4.h.

Macro Definition Documentation

◆ SM4_BLOCK_SIZE

#define SM4_BLOCK_SIZE   16

Definition at line 43 of file sm4.h.

◆ SM4_CIPHER_ALGO

#define SM4_CIPHER_ALGO   (&sm4CipherAlgo)

Definition at line 45 of file sm4.h.

◆ SM4_PRIVATE_CONTEXT

#define SM4_PRIVATE_CONTEXT

Definition at line 39 of file sm4.h.

Function Documentation

◆ sm4DecryptBlock()

void sm4DecryptBlock ( Sm4Context context,
const uint8_t *  input,
uint8_t *  output 
)

Decrypt a 16-byte block using SM4 algorithm.

Parameters
[in]contextPointer to the SM4 context
[in]inputCiphertext block to decrypt
[out]outputPlaintext block resulting from decryption

Definition at line 218 of file sm4.c.

◆ sm4Deinit()

void sm4Deinit ( Sm4Context context)

Release SM4 context.

Parameters
[in]contextPointer to the SM4 context

Definition at line 256 of file sm4.c.

◆ sm4EncryptBlock()

void sm4EncryptBlock ( Sm4Context context,
const uint8_t *  input,
uint8_t *  output 
)

Encrypt a 16-byte block using SM4 algorithm.

Parameters
[in]contextPointer to the SM4 context
[in]inputPlaintext block to encrypt
[out]outputCiphertext block resulting from encryption

Definition at line 179 of file sm4.c.

◆ sm4Init()

error_t sm4Init ( Sm4Context context,
const uint8_t *  key,
size_t  keyLen 
)

Key expansion.

Parameters
[in]contextPointer to the SM4 context to initialize
[in]keyPointer to the key
[in]keyLenLength of the key
Returns
Error code

Definition at line 137 of file sm4.c.

Variable Documentation

◆ SM4_CBC_OID

const uint8_t SM4_CBC_OID[8]
extern

Definition at line 68 of file sm4.h.

◆ SM4_CCM_OID

const uint8_t SM4_CCM_OID[8]
extern

Definition at line 109 of file sm4.c.

◆ SM4_CFB_OID

const uint8_t SM4_CFB_OID[8]
extern

Definition at line 103 of file sm4.c.

◆ SM4_CTR_OID

const uint8_t SM4_CTR_OID[8]
extern

Definition at line 105 of file sm4.c.

◆ SM4_ECB_OID

const uint8_t SM4_ECB_OID[8]
extern

Definition at line 97 of file sm4.c.

◆ SM4_GCM_OID

const uint8_t SM4_GCM_OID[8]
extern

Definition at line 107 of file sm4.c.

◆ SM4_OFB_OID

const uint8_t SM4_OFB_OID[8]
extern

Definition at line 101 of file sm4.c.

◆ SM4_XTS_OID

const uint8_t SM4_XTS_OID[8]
extern

Definition at line 111 of file sm4.c.

◆ sm4CipherAlgo

const CipherAlgo sm4CipherAlgo
extern

Definition at line 114 of file sm4.c.