cast128.c File Reference

CAST-128 encryption algorithm. More...

#include "core/crypto.h"
#include "cipher/cast128.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 S5(a, b)   s5[(a >> (8 * b)) & 0xFF]
 
#define S6(a, b)   s6[(a >> (8 * b)) & 0xFF]
 
#define S7(a, b)   s7[(a >> (8 * b)) & 0xFF]
 
#define S8(a, b)   s8[(a >> (8 * b)) & 0xFF]
 
#define F1(y, x, kr, km)
 
#define F2(y, x, kr, km)
 
#define F3(y, x, kr, km)
 

Functions

error_t cast128Init (Cast128Context *context, const uint8_t *key, size_t keyLen)
 Key expansion. More...
 
void cast128EncryptBlock (Cast128Context *context, const uint8_t *input, uint8_t *output)
 Encrypt a 8-byte block using CAST-128 algorithm. More...
 
void cast128DecryptBlock (Cast128Context *context, const uint8_t *input, uint8_t *output)
 Decrypt a 8-byte block using CAST-128 algorithm. More...
 
void cast128Deinit (Cast128Context *context)
 Release CAST-128 context. More...
 

Variables

const CipherAlgo cast128CipherAlgo
 

Detailed Description

CAST-128 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.0

Definition in file cast128.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); \
}
#define S3(a, b)
Definition: cast128.c:44
#define S1(a, b)
Definition: cast128.c:42
#define S2(a, b)
Definition: cast128.c:43
#define S4(a, b)
Definition: cast128.c:45
#define ROL32(a, n)
Definition: crypto.h:776
uint8_t x
Definition: lldp_ext_med.h:211
uint8_t t
Definition: lldp_ext_med.h:212

Definition at line 52 of file cast128.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 61 of file cast128.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 70 of file cast128.c.

◆ S1

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

Definition at line 42 of file cast128.c.

◆ S2

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

Definition at line 43 of file cast128.c.

◆ S3

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

Definition at line 44 of file cast128.c.

◆ S4

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

Definition at line 45 of file cast128.c.

◆ S5

#define S5 (   a,
  b 
)    s5[(a >> (8 * b)) & 0xFF]

Definition at line 46 of file cast128.c.

◆ S6

#define S6 (   a,
  b 
)    s6[(a >> (8 * b)) & 0xFF]

Definition at line 47 of file cast128.c.

◆ S7

#define S7 (   a,
  b 
)    s7[(a >> (8 * b)) & 0xFF]

Definition at line 48 of file cast128.c.

◆ S8

#define S8 (   a,
  b 
)    s8[(a >> (8 * b)) & 0xFF]

Definition at line 49 of file cast128.c.

◆ TRACE_LEVEL

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL

Definition at line 32 of file cast128.c.

Function Documentation

◆ cast128DecryptBlock()

void cast128DecryptBlock ( Cast128Context context,
const uint8_t *  input,
uint8_t *  output 
)

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

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

Definition at line 551 of file cast128.c.

◆ cast128Deinit()

void cast128Deinit ( Cast128Context context)

Release CAST-128 context.

Parameters
[in]contextPointer to the CAST-128 context

Definition at line 595 of file cast128.c.

◆ cast128EncryptBlock()

void cast128EncryptBlock ( Cast128Context context,
const uint8_t *  input,
uint8_t *  output 
)

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

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

Definition at line 505 of file cast128.c.

◆ cast128Init()

error_t cast128Init ( Cast128Context context,
const uint8_t *  key,
size_t  keyLen 
)

Key expansion.

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

Definition at line 398 of file cast128.c.

Variable Documentation

◆ cast128CipherAlgo

const CipherAlgo cast128CipherAlgo
Initial value:
=
{
"CAST-128",
sizeof(Cast128Context),
NULL,
NULL,
}
error_t cast128Init(Cast128Context *context, const uint8_t *key, size_t keyLen)
Key expansion.
Definition: cast128.c:398
void cast128EncryptBlock(Cast128Context *context, const uint8_t *input, uint8_t *output)
Encrypt a 8-byte block using CAST-128 algorithm.
Definition: cast128.c:505
void cast128Deinit(Cast128Context *context)
Release CAST-128 context.
Definition: cast128.c:595
void cast128DecryptBlock(Cast128Context *context, const uint8_t *input, uint8_t *output)
Decrypt a 8-byte block using CAST-128 algorithm.
Definition: cast128.c:551
#define CAST128_BLOCK_SIZE
Definition: cast128.h:38
void(* CipherAlgoDeinit)(void *context)
Definition: crypto.h:983
void(* CipherAlgoDecryptBlock)(void *context, const uint8_t *input, uint8_t *output)
Definition: crypto.h:980
error_t(* CipherAlgoInit)(void *context, const uint8_t *key, size_t keyLen)
Definition: crypto.h:968
void(* CipherAlgoEncryptBlock)(void *context, const uint8_t *input, uint8_t *output)
Definition: crypto.h:977
@ CIPHER_ALGO_TYPE_BLOCK
Definition: crypto.h:932
CAST-128 algorithm context.
Definition: cast128.h:53

Definition at line 375 of file cast128.c.