blowfish.c File Reference

Blowfish encryption algorithm. More...

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

Go to the source code of this file.

Macros

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL
 

Functions

error_t blowfishInit (BlowfishContext *context, const uint8_t *key, size_t keyLen)
 Initialize a Blowfish context using the supplied key. More...
 
error_t blowfishInitState (BlowfishContext *context)
 Blowfish state initialization. More...
 
error_t blowfishExpandKey (BlowfishContext *context, const uint8_t *salt, size_t saltLen, const uint8_t *key, size_t keyLen)
 Key expansion. More...
 
void blowfishEncryptBlock (BlowfishContext *context, const uint8_t *input, uint8_t *output)
 Encrypt a 8-byte block using Blowfish algorithm. More...
 
void blowfishDecryptBlock (BlowfishContext *context, const uint8_t *input, uint8_t *output)
 Decrypt a 8-byte block using Blowfish algorithm. More...
 
void blowfishXorBlock (uint8_t *data, const uint8_t *salt, size_t saltLen, size_t *saltIndex)
 XOR data block with random salt. More...
 
void blowfishDeinit (BlowfishContext *context)
 Release Blowfish context. More...
 

Variables

const CipherAlgo blowfishCipherAlgo
 

Detailed Description

Blowfish 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

Blowfish 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.0

Definition in file blowfish.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL

Definition at line 37 of file blowfish.c.

Function Documentation

◆ blowfishDecryptBlock()

void blowfishDecryptBlock ( BlowfishContext context,
const uint8_t *  input,
uint8_t *  output 
)

Decrypt a 8-byte block using Blowfish algorithm.

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

Definition at line 461 of file blowfish.c.

◆ blowfishDeinit()

void blowfishDeinit ( BlowfishContext context)

Release Blowfish context.

Parameters
[in]contextPointer to the Blowfish context

Definition at line 548 of file blowfish.c.

◆ blowfishEncryptBlock()

void blowfishEncryptBlock ( BlowfishContext context,
const uint8_t *  input,
uint8_t *  output 
)

Encrypt a 8-byte block using Blowfish algorithm.

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

Definition at line 411 of file blowfish.c.

◆ blowfishExpandKey()

error_t blowfishExpandKey ( BlowfishContext context,
const uint8_t *  salt,
size_t  saltLen,
const uint8_t *  key,
size_t  keyLen 
)

Key expansion.

Parameters
[in]contextPointer to the Blowfish context
[in]saltRandom salt
[in]saltLenLength of the random salt, in bytes
[in]keySecret key
[in]keyLenLength of the secret key, in bytes
Returns
Error code

Definition at line 291 of file blowfish.c.

◆ blowfishInit()

error_t blowfishInit ( BlowfishContext context,
const uint8_t *  key,
size_t  keyLen 
)

Initialize a Blowfish context using the supplied key.

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

Definition at line 227 of file blowfish.c.

◆ blowfishInitState()

error_t blowfishInitState ( BlowfishContext context)

Blowfish state initialization.

Parameters
[in]contextPointer to the Blowfish context
Returns
Error code

Definition at line 257 of file blowfish.c.

◆ blowfishXorBlock()

void blowfishXorBlock ( uint8_t *  data,
const uint8_t *  salt,
size_t  saltLen,
size_t *  saltIndex 
)

XOR data block with random salt.

Parameters
[in,out]dataPointer the data block (16 bytes)
[in]saltPointer to the random salt (16 bytes)
[in]saltLenLength of the salt, in bytes
[in,out]saltIndexCurrent salt index

Definition at line 512 of file blowfish.c.

Variable Documentation

◆ blowfishCipherAlgo

const CipherAlgo blowfishCipherAlgo
Initial value:
=
{
"Blowfish",
sizeof(BlowfishContext),
NULL,
NULL,
}
void blowfishEncryptBlock(BlowfishContext *context, const uint8_t *input, uint8_t *output)
Encrypt a 8-byte block using Blowfish algorithm.
Definition: blowfish.c:411
error_t blowfishInit(BlowfishContext *context, const uint8_t *key, size_t keyLen)
Initialize a Blowfish context using the supplied key.
Definition: blowfish.c:227
void blowfishDeinit(BlowfishContext *context)
Release Blowfish context.
Definition: blowfish.c:548
void blowfishDecryptBlock(BlowfishContext *context, const uint8_t *input, uint8_t *output)
Decrypt a 8-byte block using Blowfish algorithm.
Definition: blowfish.c:461
#define BLOWFISH_BLOCK_SIZE
Definition: blowfish.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
Blowfish algorithm context.
Definition: blowfish.h:53

Definition at line 204 of file blowfish.c.