camellia.c File Reference

Camellia encryption algorithm. More...

#include "core/crypto.h"
#include "cipher/camellia.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL
 
#define F(xl, xr, kl, kr)
 
#define FL(xl, xr, kl, kr)
 
#define FL_INV(yl, yr, kl, kr)
 
#define S(zl, zr)
 
#define P(zl, zr)
 
#define ROUND(left1, left2, right1, right2, k1, k2)
 
#define KL   0
 
#define KR   4
 
#define KA   8
 
#define KB   12
 
#define L   0
 
#define R   64
 

Functions

error_t camelliaInit (CamelliaContext *context, const uint8_t *key, size_t keyLen)
 Initialize a Camellia context using the supplied key. More...
 
void camelliaEncryptBlock (CamelliaContext *context, const uint8_t *input, uint8_t *output)
 Encrypt a 16-byte block using Camellia algorithm. More...
 
void camelliaDecryptBlock (CamelliaContext *context, const uint8_t *input, uint8_t *output)
 Decrypt a 16-byte block using Camellia algorithm. More...
 
void camelliaDeinit (CamelliaContext *context)
 Release Camellia context. More...
 

Variables

const uint8_t CAMELLIA128_CBC_OID [11] = {0x2A, 0x83, 0x08, 0x8C, 0x9A, 0x4B, 0x3D, 0x01, 0x01, 0x01, 0x02}
 
const uint8_t CAMELLIA192_CBC_OID [11] = {0x2A, 0x83, 0x08, 0x8C, 0x9A, 0x4B, 0x3D, 0x01, 0x01, 0x01, 0x03}
 
const uint8_t CAMELLIA256_CBC_OID [11] = {0x2A, 0x83, 0x08, 0x8C, 0x9A, 0x4B, 0x3D, 0x01, 0x01, 0x01, 0x04}
 
const CipherAlgo camelliaCipherAlgo
 

Detailed Description

Camellia 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.

Description

Camellia is an encryption algorithm designed to encipher and decipher blocks of 128 bits under control of a 128/192/256-bit secret key

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

Definition in file camellia.c.

Macro Definition Documentation

◆ F

#define F (   xl,
  xr,
  kl,
  kr 
)
Value:
{ \
xl = xl ^ kl; \
xl = xr ^ kr; \
S(xl, xr); \
P(xl, xr); \
}

Definition at line 48 of file camellia.c.

◆ FL

#define FL (   xl,
  xr,
  kl,
  kr 
)
Value:
{ \
temp1 = (xl & kl); \
xr ^= ROL32(temp1, 1); \
xl ^= (xr | kr); \
}

Definition at line 57 of file camellia.c.

◆ FL_INV

#define FL_INV (   yl,
  yr,
  kl,
  kr 
)
Value:
{ \
yl ^= (yr | kr); \
temp1 = (yl & kl); \
yr ^= ROL32(temp1, 1); \
}

Definition at line 65 of file camellia.c.

◆ KA

#define KA   8

Definition at line 108 of file camellia.c.

◆ KB

#define KB   12

Definition at line 109 of file camellia.c.

◆ KL

#define KL   0

Definition at line 106 of file camellia.c.

◆ KR

#define KR   4

Definition at line 107 of file camellia.c.

◆ L

#define L   0

Definition at line 110 of file camellia.c.

◆ P

#define P (   zl,
  zr 
)
Value:
{ \
zl ^= ROL32(zr, 8); \
zr ^= ROL32(zl, 16); \
zl ^= ROR32(zr, 8); \
zr ^= ROR32(zl, 8); \
}

Definition at line 82 of file camellia.c.

◆ R

#define R   64

Definition at line 111 of file camellia.c.

◆ ROUND

#define ROUND (   left1,
  left2,
  right1,
  right2,
  k1,
  k2 
)
Value:
{ \
temp1 = left1 ^ k1; \
temp2 = left2 ^ k2; \
S(temp1, temp2); \
P(temp1, temp2); \
temp1 ^= right2; \
temp2 ^= right1; \
right1 = left1; \
right2 = left2; \
left1 = temp2; \
left2 = temp1; \
}

Definition at line 91 of file camellia.c.

◆ S

#define S (   zl,
  zr 
)
Value:
{ \
zl = (sbox1[(zl >> 24) & 0xFF] << 24) | (sbox2[(zl >> 16) & 0xFF] << 16) | \
(sbox3[(zl >> 8) & 0xFF] << 8) | sbox4[zl & 0xFF]; \
zr = (sbox2[(zr >> 24) & 0xFF] << 24) | (sbox3[(zr >> 16) & 0xFF] << 16) | \
(sbox4[(zr >> 8) & 0xFF] << 8) | sbox1[zr & 0xFF]; \
}

Definition at line 73 of file camellia.c.

◆ TRACE_LEVEL

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL

Definition at line 37 of file camellia.c.

Function Documentation

◆ camelliaDecryptBlock()

void camelliaDecryptBlock ( CamelliaContext context,
const uint8_t *  input,
uint8_t *  output 
)

Decrypt a 16-byte block using Camellia algorithm.

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

Definition at line 512 of file camellia.c.

◆ camelliaDeinit()

void camelliaDeinit ( CamelliaContext context)

Release Camellia context.

Parameters
[in]contextPointer to the Camellia context

Definition at line 578 of file camellia.c.

◆ camelliaEncryptBlock()

void camelliaEncryptBlock ( CamelliaContext context,
const uint8_t *  input,
uint8_t *  output 
)

Encrypt a 16-byte block using Camellia algorithm.

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

Definition at line 444 of file camellia.c.

◆ camelliaInit()

error_t camelliaInit ( CamelliaContext context,
const uint8_t *  key,
size_t  keyLen 
)

Initialize a Camellia context using the supplied key.

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

Definition at line 309 of file camellia.c.

Variable Documentation

◆ CAMELLIA128_CBC_OID

const uint8_t CAMELLIA128_CBC_OID[11] = {0x2A, 0x83, 0x08, 0x8C, 0x9A, 0x4B, 0x3D, 0x01, 0x01, 0x01, 0x02}

Definition at line 279 of file camellia.c.

◆ CAMELLIA192_CBC_OID

const uint8_t CAMELLIA192_CBC_OID[11] = {0x2A, 0x83, 0x08, 0x8C, 0x9A, 0x4B, 0x3D, 0x01, 0x01, 0x01, 0x03}

Definition at line 281 of file camellia.c.

◆ CAMELLIA256_CBC_OID

const uint8_t CAMELLIA256_CBC_OID[11] = {0x2A, 0x83, 0x08, 0x8C, 0x9A, 0x4B, 0x3D, 0x01, 0x01, 0x01, 0x04}

Definition at line 283 of file camellia.c.

◆ camelliaCipherAlgo

void camelliaDecryptBlock(CamelliaContext *context, const uint8_t *input, uint8_t *output)
Decrypt a 16-byte block using Camellia algorithm.
Definition: camellia.c:512
#define ROR32(a, n)
Definition: crypto.h:803
void(* CipherAlgoEncryptBlock)(void *context, const uint8_t *input, uint8_t *output)
Definition: crypto.h:1009
@ CIPHER_ALGO_TYPE_BLOCK
Definition: crypto.h:953
void(* CipherAlgoDecryptBlock)(void *context, const uint8_t *input, uint8_t *output)
Definition: crypto.h:1012
error_t(* CipherAlgoInit)(void *context, const uint8_t *key, size_t keyLen)
Definition: crypto.h:1000
error_t camelliaInit(CamelliaContext *context, const uint8_t *key, size_t keyLen)
Initialize a Camellia context using the supplied key.
Definition: camellia.c:309
#define ROL32(a, n)
Definition: crypto.h:797
Camellia algorithm context.
Definition: camellia.h:66
#define CAMELLIA_BLOCK_SIZE
Definition: camellia.h:38
void(* CipherAlgoDeinit)(void *context)
Definition: crypto.h:1015
void camelliaDeinit(CamelliaContext *context)
Release Camellia context.
Definition: camellia.c:578
void camelliaEncryptBlock(CamelliaContext *context, const uint8_t *input, uint8_t *output)
Encrypt a 16-byte block using Camellia algorithm.
Definition: camellia.c:444