cast256.c File Reference

CAST-256 encryption algorithm. More...

#include "core/crypto.h"
#include "cipher/cast256.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL
 
#define S1(a, b)   s1[(a >> (8 * b)) & 0xFF]
 
#define S2(a, b)   s2[(a >> (8 * b)) & 0xFF]
 
#define S3(a, b)   s3[(a >> (8 * b)) & 0xFF]
 
#define S4(a, b)   s4[(a >> (8 * b)) & 0xFF]
 
#define F1(y, x, kr, km)
 
#define F2(y, x, kr, km)
 
#define F3(y, x, kr, km)
 
#define Q(a, b, c, d, kr, km)
 
#define QBAR(a, b, c, d, kr, km)
 
#define W(a, b, c, d, e, f, g, h, tr, tm)
 

Functions

error_t cast256Init (Cast256Context *context, const uint8_t *key, size_t keyLen)
 Key expansion. More...
 
void cast256EncryptBlock (Cast256Context *context, const uint8_t *input, uint8_t *output)
 Encrypt a 8-byte block using CAST-256 algorithm. More...
 
void cast256DecryptBlock (Cast256Context *context, const uint8_t *input, uint8_t *output)
 Decrypt a 8-byte block using CAST-256 algorithm. More...
 
void cast256Deinit (Cast256Context *context)
 Release CAST-256 context. More...
 

Variables

const CipherAlgo cast256CipherAlgo
 

Detailed Description

CAST-256 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 cast256.c.

Macro Definition Documentation

◆ F1

#define F1 (   y,
  x,
  kr,
  km 
)
Value:
{ \
uint32_t t; \
t = km + x; \
t = ROL32(t, kr); \
y ^= ((S1(t, 3) ^ S2(t, 2)) - S3(t, 1)) + S4(t, 0); \
}

Definition at line 48 of file cast256.c.

◆ F2

#define F2 (   y,
  x,
  kr,
  km 
)
Value:
{ \
uint32_t t; \
t = km ^ x; \
t = ROL32(t, kr); \
y ^= ((S1(t, 3) - S2(t, 2)) + S3(t, 1)) ^ S4(t, 0); \
}

Definition at line 57 of file cast256.c.

◆ F3

#define F3 (   y,
  x,
  kr,
  km 
)
Value:
{ \
uint32_t t; \
t = km - x; \
t = ROL32(t, kr); \
y ^= ((S1(t, 3) + S2(t, 2)) ^ S3(t, 1)) - S4(t, 0); \
}

Definition at line 66 of file cast256.c.

◆ Q

#define Q (   a,
  b,
  c,
  d,
  kr,
  km 
)
Value:
{ \
F1(c, d, kr[0], km[0]); \
F2(b, c, kr[1], km[1]); \
F3(a, b, kr[2], km[2]); \
F1(d, a, kr[3], km[3]); \
}

Definition at line 75 of file cast256.c.

◆ QBAR

#define QBAR (   a,
  b,
  c,
  d,
  kr,
  km 
)
Value:
{ \
F1(d, a, kr[3], km[3]); \
F3(a, b, kr[2], km[2]); \
F2(b, c, kr[1], km[1]); \
F1(c, d, kr[0], km[0]); \
}

Definition at line 84 of file cast256.c.

◆ S1

#define S1 (   a,
  b 
)    s1[(a >> (8 * b)) & 0xFF]

Definition at line 42 of file cast256.c.

◆ S2

#define S2 (   a,
  b 
)    s2[(a >> (8 * b)) & 0xFF]

Definition at line 43 of file cast256.c.

◆ S3

#define S3 (   a,
  b 
)    s3[(a >> (8 * b)) & 0xFF]

Definition at line 44 of file cast256.c.

◆ S4

#define S4 (   a,
  b 
)    s4[(a >> (8 * b)) & 0xFF]

Definition at line 45 of file cast256.c.

◆ TRACE_LEVEL

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL

Definition at line 32 of file cast256.c.

◆ W

#define W (   a,
  b,
  c,
  d,
  e,
  f,
  g,
  h,
  tr,
  tm 
)
Value:
{ \
F1(g, h, tr[0], tm[0]); \
F2(f, g, tr[1], tm[1]); \
F3(e, f, tr[2], tm[2]); \
F1(d, e, tr[3], tm[3]); \
F2(c, d, tr[4], tm[4]); \
F3(b, c, tr[5], tm[5]); \
F1(a, b, tr[6], tm[6]); \
F2(h, a, tr[7], tm[7]); \
}

Definition at line 93 of file cast256.c.

Function Documentation

◆ cast256DecryptBlock()

void cast256DecryptBlock ( Cast256Context context,
const uint8_t *  input,
uint8_t *  output 
)

Decrypt a 8-byte block using CAST-256 algorithm.

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

Definition at line 416 of file cast256.c.

◆ cast256Deinit()

void cast256Deinit ( Cast256Context context)

Release CAST-256 context.

Parameters
[in]contextPointer to the CAST-256 context

Definition at line 459 of file cast256.c.

◆ cast256EncryptBlock()

void cast256EncryptBlock ( Cast256Context context,
const uint8_t *  input,
uint8_t *  output 
)

Encrypt a 8-byte block using CAST-256 algorithm.

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

Definition at line 372 of file cast256.c.

◆ cast256Init()

error_t cast256Init ( Cast256Context context,
const uint8_t *  key,
size_t  keyLen 
)

Key expansion.

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

Definition at line 315 of file cast256.c.

Variable Documentation

◆ cast256CipherAlgo

uint8_t b
Definition: nbns_common.h:104
uint8_t a
Definition: ndp.h:411
void(* CipherAlgoEncryptBlock)(void *context, const uint8_t *input, uint8_t *output)
Definition: crypto.h:1009
uint8_t x
Definition: lldp_ext_med.h:211
@ CIPHER_ALGO_TYPE_BLOCK
Definition: crypto.h:953
uint8_t t
Definition: lldp_ext_med.h:212
error_t cast256Init(Cast256Context *context, const uint8_t *key, size_t keyLen)
Key expansion.
Definition: cast256.c:315
#define CAST256_BLOCK_SIZE
Definition: cast256.h:38
#define S3(a, b)
Definition: cast256.c:44
void cast256EncryptBlock(Cast256Context *context, const uint8_t *input, uint8_t *output)
Encrypt a 8-byte block using CAST-256 algorithm.
Definition: cast256.c:372
uint8_t h
Definition: ndp.h:302
void(* CipherAlgoDecryptBlock)(void *context, const uint8_t *input, uint8_t *output)
Definition: crypto.h:1012
#define S4(a, b)
Definition: cast256.c:45
void cast256Deinit(Cast256Context *context)
Release CAST-256 context.
Definition: cast256.c:459
error_t(* CipherAlgoInit)(void *context, const uint8_t *key, size_t keyLen)
Definition: crypto.h:1000
#define S1(a, b)
Definition: cast256.c:42
#define S2(a, b)
Definition: cast256.c:43
#define ROL32(a, n)
Definition: crypto.h:797
CAST-256 algorithm context.
Definition: cast256.h:53
void(* CipherAlgoDeinit)(void *context)
Definition: crypto.h:1015
void cast256DecryptBlock(Cast256Context *context, const uint8_t *input, uint8_t *output)
Decrypt a 8-byte block using CAST-256 algorithm.
Definition: cast256.c:416
uint8_t c
Definition: ndp.h:514