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 16-byte block using Blowfish algorithm. More...
 
void blowfishDecryptBlock (BlowfishContext *context, const uint8_t *input, uint8_t *output)
 Decrypt a 16-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...
 

Variables

const CipherAlgo blowfishCipherAlgo
 

Detailed Description

Blowfish encryption algorithm.

License

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

Copyright (C) 2010-2019 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
1.9.6

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 16-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 460 of file blowfish.c.

◆ blowfishEncryptBlock()

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

Encrypt a 16-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 410 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 290 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 226 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 256 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 511 of file blowfish.c.

Variable Documentation

◆ blowfishCipherAlgo

const CipherAlgo blowfishCipherAlgo
void(* CipherAlgoEncryptBlock)(void *context, const uint8_t *input, uint8_t *output)
Definition: crypto.h:1103
void(* CipherAlgoDecryptBlock)(void *context, const uint8_t *input, uint8_t *output)
Definition: crypto.h:1104
error_t blowfishInit(BlowfishContext *context, const uint8_t *key, size_t keyLen)
Initialize a Blowfish context using the supplied key.
Definition: blowfish.c:226
error_t(* CipherAlgoInit)(void *context, const uint8_t *key, size_t keyLen)
Definition: crypto.h:1100
void blowfishEncryptBlock(BlowfishContext *context, const uint8_t *input, uint8_t *output)
Encrypt a 16-byte block using Blowfish algorithm.
Definition: blowfish.c:410
Blowfish algorithm context.
Definition: blowfish.h:52
#define BLOWFISH_BLOCK_SIZE
Definition: blowfish.h:38
void blowfishDecryptBlock(BlowfishContext *context, const uint8_t *input, uint8_t *output)
Decrypt a 16-byte block using Blowfish algorithm.
Definition: blowfish.c:460