Skip to content

Commit

Permalink
Worked on Blowfish support
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimmetz committed Jan 14, 2024
1 parent 4187fd4 commit da36751
Show file tree
Hide file tree
Showing 36 changed files with 3,652 additions and 100 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ stamp-h[1-9]
/libfcrypto/libfcrypto_definitions.h
/setup.cfg
/tests/*.exe
/tests/fcrypto_test_blowfish_context
/tests/fcrypto_test_des3_context
/tests/fcrypto_test_error
/tests/fcrypto_test_rc4_context
Expand Down
48 changes: 25 additions & 23 deletions autogen.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Script to generate the necessary files for a msvscpp build
#
# Version: 20230104
# Version: 20240114

$WinFlex = "..\win_flex_bison\win_flex.exe"
$WinBison = "..\win_flex_bison\win_bison.exe"
Expand All @@ -22,35 +22,37 @@ If (Test-Path "${Prefix}.net")
Get-Content -Path "${Prefix}.net\${Prefix}.net.rc.in" | % { $_ -Replace "@VERSION@","${Version}" } > "${Prefix}.net\${Prefix}.net.rc"
}

$NamePrefix = ""

ForEach (${DirectoryElement} in Get-ChildItem -Path "${Library}\*.l")
ForEach (${LibraryDirectory} in Get-ChildItem -Directory -Path "lib*")
{
$OutputFile = ${DirectoryElement} -Replace ".l$",".c"
$NamePrefix = ""

$NamePrefix = Split-Path -path ${DirectoryElement} -leaf
$NamePrefix = ${NamePrefix} -Replace ".l$","_"
ForEach (${DirectoryElement} in Get-ChildItem -Path "${LibraryDirectory}\*.l")
{
$OutputFile = ${DirectoryElement} -Replace ".l$",".c"

Write-Host "Running: ${WinFlex} -Cf ${DirectoryElement}"
$NamePrefix = Split-Path -path ${DirectoryElement} -leaf
$NamePrefix = ${NamePrefix} -Replace ".l$","_"

# PowerShell will raise NativeCommandError if win_flex writes to stdout or stderr
# therefore 2>&1 is added and the output is stored in a variable.
$Output = Invoke-Expression -Command "& '${WinFlex}' -Cf ${DirectoryElement} 2>&1"
Write-Host ${Output}
Write-Host "Running: ${WinFlex} -Cf ${DirectoryElement}"

# Moving manually since win_flex -o <filename> does not provide the expected behavior.
Move-Item "lex.yy.c" ${OutputFile} -force
}
# PowerShell will raise NativeCommandError if win_flex writes to stdout or stderr
# therefore 2>&1 is added and the output is stored in a variable.
$Output = Invoke-Expression -Command "& '${WinFlex}' -Cf ${DirectoryElement} 2>&1"
Write-Host ${Output}

ForEach (${DirectoryElement} in Get-ChildItem -Path "${Library}\*.y")
{
$OutputFile = ${DirectoryElement} -Replace ".y$",".c"
# Moving manually since win_flex -o <filename> does not provide the expected behavior.
Move-Item "lex.yy.c" ${OutputFile} -force
}
ForEach (${DirectoryElement} in Get-ChildItem -Path "${LibraryDirectory}\*.y")
{
$OutputFile = ${DirectoryElement} -Replace ".y$",".c"

Write-Host "Running: ${WinBison} -d -v -l -p ${NamePrefix} -o ${OutputFile} ${DirectoryElement}"
Write-Host "Running: ${WinBison} -d -v -l -p ${NamePrefix} -o ${OutputFile} ${DirectoryElement}"

# PowerShell will raise NativeCommandError if win_bison writes to stdout or stderr
# therefore 2>&1 is added and the output is stored in a variable.
$Output = Invoke-Expression -Command "& '${WinBison}' -d -v -l -p ${NamePrefix} -o ${OutputFile} ${DirectoryElement} 2>&1"
Write-Host ${Output}
# PowerShell will raise NativeCommandError if win_bison writes to stdout or stderr
# therefore 2>&1 is added and the output is stored in a variable.
$Output = Invoke-Expression -Command "& '${WinBison}' -d -v -l -p ${NamePrefix} -o ${OutputFile} ${DirectoryElement} 2>&1"
Write-Host ${Output}
}
}

2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ AC_PREREQ([2.71])

AC_INIT(
[libfcrypto],
[20240113],
[20240114],
[joachim.metz@gmail.com])

AC_CONFIG_SRCDIR(
Expand Down
45 changes: 45 additions & 0 deletions include/libfcrypto.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,51 @@ int libfcrypto_error_backtrace_sprint(
char *string,
size_t size );

/* -------------------------------------------------------------------------
* Blowfish context functions
* ------------------------------------------------------------------------- */

/* Creates a Blowfish context
* Make sure the value context is referencing, is set to NULL
* Returns 1 if successful or -1 on error
*/
LIBFCRYPTO_EXTERN \
int libfcrypto_blowfish_context_initialize(
libfcrypto_blowfish_context_t **context,
libfcrypto_error_t **error );

/* Frees a Blowfish context
* Returns 1 if successful or -1 on error
*/
LIBFCRYPTO_EXTERN \
int libfcrypto_blowfish_context_free(
libfcrypto_blowfish_context_t **context,
libfcrypto_error_t **error );

/* Sets the key
* Returns 1 if successful or -1 on error
*/
LIBFCRYPTO_EXTERN \
int libfcrypto_blowfish_context_set_key(
libfcrypto_blowfish_context_t *context,
const uint8_t *key,
size_t key_bit_size,
libfcrypto_error_t **error );

/* De- or encrypts a block of data using Blowfish-ECB (Electronic CodeBook)
* The size must be a multitude of the Blowfish block size (8 byte)
* Returns 1 if successful or -1 on error
*/
LIBFCRYPTO_EXTERN \
int libfcrypto_blowfish_crypt_ecb(
libfcrypto_blowfish_context_t *context,
int mode,
const uint8_t *input_data,
size_t input_data_size,
uint8_t *output_data,
size_t output_data_size,
libfcrypto_error_t **error );

/* -------------------------------------------------------------------------
* DES3 context functions
* ------------------------------------------------------------------------- */
Expand Down
8 changes: 8 additions & 0 deletions include/libfcrypto/definitions.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ enum LIBFCRYPTO_CRYPT_MODES
LIBFCRYPTO_CRYPT_MODE_ENCRYPT = 1
};

/* The Blowfish crypt modes
*/
enum LIBFCRYPTO_BLOWFISH_CRYPT_MODES
{
LIBFCRYPTO_BLOWFISH_CRYPT_MODE_DECRYPT = 0,
LIBFCRYPTO_BLOWFISH_CRYPT_MODE_ENCRYPT = 1
};

/* The DES3 crypt modes
*/
enum LIBFCRYPTO_DES3_CRYPT_MODES
Expand Down
1 change: 1 addition & 0 deletions include/libfcrypto/types.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ typedef int64_t off64_t;

/* The following type definitions hide internal data structures
*/
typedef intptr_t libfcrypto_blowfish_context_t;
typedef intptr_t libfcrypto_des3_context_t;
typedef intptr_t libfcrypto_rc4_context_t;
typedef intptr_t libfcrypto_serpent_context_t;
Expand Down
2 changes: 1 addition & 1 deletion libfcrypto.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ year_of_creation: "2017"

[library]
description: "Library to support encryption formats"
public_types: ["des3_context", "rc4_context", "serpent_context"]
public_types: ["blowfish_context", "des3_context", "rc4_context", "serpent_context"]

[pypi]
appveyor_token: "VHuZiUWgTqTciKE2nsv/Liq2uBy0XjvALnnciAypD5uQOP4lt3JOyQt3cI5WdBIZPk8lfBYRMjVcovICCImAjvemG7wsI9dENfixnZ/pbhpQBC9QC0x6CKYVWtKzaB35JvDAiLqGGSDl7W5heVHyw0kDJsn1pmr0oMC0bA1fc3/hVtTNnVvTo1q1DijMVeXHVyiAf/eqbAsQyTOmeDLiTxZgwp7hYSKrtVkorSdlW/Qr3OSuLxixKPmNcfqtMagDAQO9aoN0UoKmipDM+mpvNqSUQRxQw4t2rLi4kdLjaRw="
Expand Down
1 change: 1 addition & 0 deletions libfcrypto/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ lib_LTLIBRARIES = libfcrypto.la

libfcrypto_la_SOURCES = \
libfcrypto.c \
libfcrypto_blowfish_context.c libfcrypto_blowfish_context.h \
libfcrypto_definitions.h \
libfcrypto_des3_context.c libfcrypto_des3_context.h \
libfcrypto_extern.h \
Expand Down
Loading

0 comments on commit da36751

Please sign in to comment.