Skip to content

Commit

Permalink
Rename crypt->crypto
Browse files Browse the repository at this point in the history
  • Loading branch information
chpock committed Jul 8, 2024
1 parent 38040c3 commit ec15990
Show file tree
Hide file tree
Showing 17 changed files with 462 additions and 461 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
2024-07-08 Konstantin Kushnir <[email protected]>
* Add procedures for AES encryption/decryption
* Rename crypt->crypto

2024-07-07 Konstantin Kushnir <[email protected]>
* Add basic cryptographic functions
Expand Down
40 changes: 20 additions & 20 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -657,8 +657,8 @@ MAKE_LIB
EGREP
GREP
COOKFS_PKGCONFIG_USECPKGCONFIG
COOKFS_PKGCONFIG_FEATURE_CRYPT
COOKFS_PKGCONFIG_USECCRYPT
COOKFS_PKGCONFIG_FEATURE_CRYPTO
COOKFS_PKGCONFIG_USECCRYPTO
COOKFS_PKGCONFIG_USETCLCMDS
COOKFS_PKGCONFIG_USECWRITER
COOKFS_PKGCONFIG_USECVFS
Expand Down Expand Up @@ -802,7 +802,7 @@ enable_c_writerchannel
enable_c_pkgconfig
enable_c_vfs
enable_c_writer
enable_c_crypt
enable_c_crypto
enable_tcl_commands
'
ac_precious_vars='build_alias
Expand Down Expand Up @@ -1453,7 +1453,7 @@ Optional Features:
--disable-c-pkgconfig Use pkgconfig written in C. Defaults to true
--disable-c-vfs Use VFS support written in C. Defaults to true
--disable-c-writer Use writer handler written in C. Defaults to true
--disable-c-crypt Use crypt functions written in C. Defaults to true
--disable-c-crypto Use crypto functions written in C. Defaults to true
--disable-tcl-commands Enable Tcl commands for objects. Defaults to true
Optional Packages:
Expand Down Expand Up @@ -8691,12 +8691,12 @@ else $as_nop
USECWRITER=yes
fi

# Check whether --enable-c-crypt was given.
if test ${enable_c_crypt+y}
# Check whether --enable-c-crypto was given.
if test ${enable_c_crypto+y}
then :
enableval=$enable_c_crypt; USECCRYPT=${enableval}
enableval=$enable_c_crypto; USECCRYPTO=${enableval}
else $as_nop
USECCRYPT=yes
USECCRYPTO=yes
fi

# Check whether --enable-tcl-commands was given.
Expand Down Expand Up @@ -9409,19 +9409,19 @@ else
USECWRITERCHAN="no"
# c-writer requires c-pages
USECWRITER="no"
# c-crypt requires c-pages
USECCRYPT="no"
# c-crypto requires c-pages
USECCRYPTO="no"
fi

if test ${USECCRYPT} = yes; then
printf "%s\n" "#define COOKFS_USECRYPT 1" >>confdefs.h
if test ${USECCRYPTO} = yes; then
printf "%s\n" "#define COOKFS_USECRYPTO 1" >>confdefs.h

printf "%s\n" "#define COOKFS_USECCRYPT 1" >>confdefs.h
printf "%s\n" "#define COOKFS_USECCRYPTO 1" >>confdefs.h

COOKFS_PKGCONFIG_USECCRYPT=1
COOKFS_PKGCONFIG_FEATURE_CRYPT=1
COOKFS_PKGCONFIG_USECCRYPTO=1
COOKFS_PKGCONFIG_FEATURE_CRYPTO=1

vars="crypt.c cryptCmd.c"
vars="crypto.c cryptoCmd.c"
for i in $vars; do
case $i in
\$*)
Expand Down Expand Up @@ -9543,8 +9543,8 @@ if test ${USECCRYPT} = yes; then

fi
else
COOKFS_PKGCONFIG_USECCRYPT=0
COOKFS_PKGCONFIG_FEATURE_CRYPT=0
COOKFS_PKGCONFIG_USECCRYPTO=0
COOKFS_PKGCONFIG_FEATURE_CRYPTO=0
fi

if test ${USECFSINDEX} = yes; then
Expand Down Expand Up @@ -9835,9 +9835,9 @@ if test ${USECPKGCONFIG} = yes; then

printf "%s\n" "#define COOKFS_PKGCONFIG_USETCLCMDS $COOKFS_PKGCONFIG_USETCLCMDS" >>confdefs.h

printf "%s\n" "#define COOKFS_PKGCONFIG_USECCRYPT $COOKFS_PKGCONFIG_USECCRYPT" >>confdefs.h
printf "%s\n" "#define COOKFS_PKGCONFIG_USECCRYPTO $COOKFS_PKGCONFIG_USECCRYPTO" >>confdefs.h

printf "%s\n" "#define COOKFS_PKGCONFIG_FEATURE_CRYPT $COOKFS_PKGCONFIG_FEATURE_CRYPT" >>confdefs.h
printf "%s\n" "#define COOKFS_PKGCONFIG_FEATURE_CRYPTO $COOKFS_PKGCONFIG_FEATURE_CRYPTO" >>confdefs.h


printf "%s\n" "#define COOKFS_USECPKGCONFIG 1" >>confdefs.h
Expand Down
30 changes: 15 additions & 15 deletions configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ AC_ARG_ENABLE(c-writerchannel, [ --disable-c-writerchannel Use writer handler w
AC_ARG_ENABLE(c-pkgconfig, [ --disable-c-pkgconfig Use pkgconfig written in C. Defaults to true], USECPKGCONFIG=${enableval}, USECPKGCONFIG=yes)
AC_ARG_ENABLE(c-vfs, [ --disable-c-vfs Use VFS support written in C. Defaults to true], USECVFS=${enableval}, USECVFS=yes)
AC_ARG_ENABLE(c-writer, [ --disable-c-writer Use writer handler written in C. Defaults to true], USECWRITER=${enableval}, USECWRITER=yes)
AC_ARG_ENABLE(c-crypt, [ --disable-c-crypt Use crypt functions written in C. Defaults to true], USECCRYPT=${enableval}, USECCRYPT=yes)
AC_ARG_ENABLE(c-crypto, [ --disable-c-crypto Use crypto functions written in C. Defaults to true], USECCRYPTO=${enableval}, USECCRYPTO=yes)
AC_ARG_ENABLE(tcl-commands, [ --disable-tcl-commands Enable Tcl commands for objects. Defaults to true], USETCLCMDS=${enableval}, USETCLCMDS=yes)


Expand Down Expand Up @@ -298,16 +298,16 @@ else
USECWRITERCHAN="no"
# c-writer requires c-pages
USECWRITER="no"
# c-crypt requires c-pages
USECCRYPT="no"
# c-crypto requires c-pages
USECCRYPTO="no"
fi

if test ${USECCRYPT} = yes; then
AC_DEFINE(COOKFS_USECRYPT)
AC_DEFINE(COOKFS_USECCRYPT)
COOKFS_PKGCONFIG_USECCRYPT=1
COOKFS_PKGCONFIG_FEATURE_CRYPT=1
TEA_ADD_SOURCES([crypt.c cryptCmd.c])
if test ${USECCRYPTO} = yes; then
AC_DEFINE(COOKFS_USECRYPTO)
AC_DEFINE(COOKFS_USECCRYPTO)
COOKFS_PKGCONFIG_USECCRYPTO=1
COOKFS_PKGCONFIG_FEATURE_CRYPTO=1
TEA_ADD_SOURCES([crypto.c cryptoCmd.c])
TEA_ADD_SOURCES([7zip/C/Aes.c 7zip/C/AesOpt.c 7zip/C/Sha256.c 7zip/C/Sha256Opt.c])
if test "${TEA_PLATFORM}" = "windows" ; then
TEA_ADD_LIBS([-lbcrypt])
Expand All @@ -318,8 +318,8 @@ if test ${USECCRYPT} = yes; then
TEA_ADD_SOURCES([7zip/C/CpuArch.c])
fi
else
COOKFS_PKGCONFIG_USECCRYPT=0
COOKFS_PKGCONFIG_FEATURE_CRYPT=0
COOKFS_PKGCONFIG_USECCRYPTO=0
COOKFS_PKGCONFIG_FEATURE_CRYPTO=0
fi

if test ${USECFSINDEX} = yes; then
Expand Down Expand Up @@ -401,8 +401,8 @@ AC_SUBST(COOKFS_PKGCONFIG_FEATURE_METADATA)
AC_SUBST(COOKFS_PKGCONFIG_USECVFS)
AC_SUBST(COOKFS_PKGCONFIG_USECWRITER)
AC_SUBST(COOKFS_PKGCONFIG_USETCLCMDS)
AC_SUBST(COOKFS_PKGCONFIG_USECCRYPT)
AC_SUBST(COOKFS_PKGCONFIG_FEATURE_CRYPT)
AC_SUBST(COOKFS_PKGCONFIG_USECCRYPTO)
AC_SUBST(COOKFS_PKGCONFIG_FEATURE_CRYPTO)

if test ${USECPKGCONFIG} = yes; then
COOKFS_PKGCONFIG_USECPKGCONFIG=1
Expand All @@ -420,8 +420,8 @@ if test ${USECPKGCONFIG} = yes; then
AC_DEFINE_UNQUOTED(COOKFS_PKGCONFIG_USECVFS, $COOKFS_PKGCONFIG_USECVFS)
AC_DEFINE_UNQUOTED(COOKFS_PKGCONFIG_USECWRITER, $COOKFS_PKGCONFIG_USECWRITER)
AC_DEFINE_UNQUOTED(COOKFS_PKGCONFIG_USETCLCMDS, $COOKFS_PKGCONFIG_USETCLCMDS)
AC_DEFINE_UNQUOTED(COOKFS_PKGCONFIG_USECCRYPT, $COOKFS_PKGCONFIG_USECCRYPT)
AC_DEFINE_UNQUOTED(COOKFS_PKGCONFIG_FEATURE_CRYPT, $COOKFS_PKGCONFIG_FEATURE_CRYPT)
AC_DEFINE_UNQUOTED(COOKFS_PKGCONFIG_USECCRYPTO, $COOKFS_PKGCONFIG_USECCRYPTO)
AC_DEFINE_UNQUOTED(COOKFS_PKGCONFIG_FEATURE_CRYPTO, $COOKFS_PKGCONFIG_FEATURE_CRYPTO)

AC_DEFINE(COOKFS_USECPKGCONFIG)
else
Expand Down
14 changes: 7 additions & 7 deletions generic/cookfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

#include "cookfs.h"
#include "crypt.h"
#include "crypto.h"

#ifdef COOKFS_USECPAGES
#include "pagesCmd.h"
Expand All @@ -34,9 +34,9 @@
#include "writerchannelCmd.h"
#endif /* COOKFS_USECWRITERCHAN */

#ifdef COOKFS_USECCRYPT
#include "cryptCmd.h"
#endif /* COOKFS_USECCRYPT */
#ifdef COOKFS_USECCRYPTO
#include "cryptoCmd.h"
#endif /* COOKFS_USECCRYPTO */

/*
*----------------------------------------------------------------------
Expand Down Expand Up @@ -123,10 +123,10 @@ Cookfs_Init(Tcl_Interp *interp) // cppcheck-suppress unusedFunction
return TCL_ERROR;
}

#if defined(COOKFS_USECCRYPT)
Cookfs_CryptInit();
#if defined(COOKFS_USECCRYPTO)
Cookfs_CryptoInit();
#if defined(COOKFS_USETCLCMDS)
if (Cookfs_InitCryptCmd(interp) != TCL_OK) {
if (Cookfs_InitCryptoCmd(interp) != TCL_OK) {
return TCL_ERROR;
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions generic/cookfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ static Tcl_Config const cookfs_pkgconfig[] = {
{"c-writerchannel", STRINGIFY(COOKFS_PKGCONFIG_USECWRITERCHAN)},
{"c-vfs", STRINGIFY(COOKFS_PKGCONFIG_USECVFS)},
{"c-writer", STRINGIFY(COOKFS_PKGCONFIG_USECWRITER)},
{"c-crypt", STRINGIFY(COOKFS_PKGCONFIG_USECCRYPT)},
{"feature-crypt", STRINGIFY(COOKFS_PKGCONFIG_FEATURE_CRYPT)},
{"c-crypto", STRINGIFY(COOKFS_PKGCONFIG_USECCRYPTO)},
{"feature-crypto", STRINGIFY(COOKFS_PKGCONFIG_FEATURE_CRYPTO)},
{"feature-aside", STRINGIFY(COOKFS_PKGCONFIG_FEATURE_ASIDE)},
{"feature-bzip2", STRINGIFY(COOKFS_PKGCONFIG_USEBZ2)},
{"feature-lzma", STRINGIFY(COOKFS_PKGCONFIG_USELZMA)},
Expand Down
8 changes: 0 additions & 8 deletions generic/cryptCmd.h

This file was deleted.

6 changes: 3 additions & 3 deletions generic/crypt.c → generic/crypto.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
* crypt.c
* crypto.c
*
* Provides implementation of cryptographic functions
*
* (c) 2024 Konstantin Kushnir
*/

#include "cookfs.h"
#include "crypt.h"
#include "crypto.h"

// for getpid()
#include <unistd.h>
Expand All @@ -28,7 +28,7 @@
#include "../7zip/C/Aes.h"
#include "../7zip/C/Sha256.h"

void Cookfs_CryptInit(void) {
void Cookfs_CryptoInit(void) {
Sha256Prepare();
AesGenTables();
}
Expand Down
8 changes: 4 additions & 4 deletions generic/crypt.h → generic/crypto.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* (c) 2014 Konstantin Kushnir */

#ifndef COOKFS_CRYPT_H
#define COOKFS_CRYPT_H 1
#ifndef COOKFS_CRYPTO_H
#define COOKFS_CRYPTO_H 1

#include "pageObj.h"

Expand All @@ -10,7 +10,7 @@

#define COOKFS_ENCRYPT_KEY_SIZE 32

void Cookfs_CryptInit(void);
void Cookfs_CryptoInit(void);

void Cookfs_RandomGenerate(Tcl_Interp *interp, unsigned char *buf, Tcl_Size size);
void Cookfs_Pbkdf2Hmac(unsigned char *secret, Tcl_Size secretSize,
Expand All @@ -20,4 +20,4 @@ void Cookfs_Pbkdf2Hmac(unsigned char *secret, Tcl_Size secretSize,
void Cookfs_AesEncrypt(Cookfs_PageObj pg, unsigned char *key);
int Cookfs_AesDecrypt(Cookfs_PageObj pg, unsigned char *key);

#endif /* COOKFS_CRYPT_H */
#endif /* COOKFS_CRYPTO_H */
34 changes: 17 additions & 17 deletions generic/cryptCmd.c → generic/cryptoCmd.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/*
* cryptCmd.c
* cryptoCmd.c
*
* Provides Tcl commands for cryptographic functions
*
* (c) 2024 Konstantin Kushnir
*/

#include "cookfs.h"
#include "crypt.h"
#include "cryptCmd.h"
#include "crypto.h"
#include "cryptoCmd.h"

static int CookfsAesEncryptObjectCmd(ClientData clientData,
Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
Expand Down Expand Up @@ -192,30 +192,30 @@ static int CookfsPbkdf2HmacObjectCmd(ClientData clientData,
return TCL_OK;
}

int Cookfs_InitCryptCmd(Tcl_Interp *interp) {
int Cookfs_InitCryptoCmd(Tcl_Interp *interp) {

Tcl_CreateNamespace(interp, "::cookfs::c::crypt", NULL, NULL);
Tcl_CreateNamespace(interp, "::cookfs::c::crypto", NULL, NULL);

Tcl_CreateObjCommand(interp, "::cookfs::c::crypt::rng",
Tcl_CreateObjCommand(interp, "::cookfs::c::crypto::rng",
CookfsRandomGenerateObjectCmd, (ClientData) NULL, NULL);

Tcl_CreateObjCommand(interp, "::cookfs::c::crypt::pbkdf2_hmac",
Tcl_CreateObjCommand(interp, "::cookfs::c::crypto::pbkdf2_hmac",
CookfsPbkdf2HmacObjectCmd, (ClientData) NULL, NULL);

Tcl_CreateObjCommand(interp, "::cookfs::c::crypt::aes_encrypt",
Tcl_CreateObjCommand(interp, "::cookfs::c::crypto::aes_encrypt",
CookfsAesEncryptObjectCmd, (ClientData) NULL, NULL);

Tcl_CreateObjCommand(interp, "::cookfs::c::crypt::aes_decrypt",
Tcl_CreateObjCommand(interp, "::cookfs::c::crypto::aes_decrypt",
CookfsAesDecryptObjectCmd, (ClientData) NULL, NULL);

Tcl_CreateAlias(interp, "::cookfs::crypt::rng", interp,
"::cookfs::c::crypt::rng", 0, NULL);
Tcl_CreateAlias(interp, "::cookfs::crypt::pbkdf2_hmac", interp,
"::cookfs::c::crypt::pbkdf2_hmac", 0, NULL);
Tcl_CreateAlias(interp, "::cookfs::crypt::aes_encrypt", interp,
"::cookfs::c::crypt::aes_encrypt", 0, NULL);
Tcl_CreateAlias(interp, "::cookfs::crypt::aes_decrypt", interp,
"::cookfs::c::crypt::aes_decrypt", 0, NULL);
Tcl_CreateAlias(interp, "::cookfs::crypto::rng", interp,
"::cookfs::c::crypto::rng", 0, NULL);
Tcl_CreateAlias(interp, "::cookfs::crypto::pbkdf2_hmac", interp,
"::cookfs::c::crypto::pbkdf2_hmac", 0, NULL);
Tcl_CreateAlias(interp, "::cookfs::crypto::aes_encrypt", interp,
"::cookfs::c::crypto::aes_encrypt", 0, NULL);
Tcl_CreateAlias(interp, "::cookfs::crypto::aes_decrypt", interp,
"::cookfs::c::crypto::aes_decrypt", 0, NULL);

return TCL_OK;

Expand Down
8 changes: 8 additions & 0 deletions generic/cryptoCmd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* (c) 2014 Konstantin Kushnir */

#ifndef COOKFS_CRYPTOCMD_H
#define COOKFS_CRYPTOCMD_H 1

int Cookfs_InitCryptoCmd(Tcl_Interp *interp);

#endif /* COOKFS_CRYPTOCMD_H */
8 changes: 4 additions & 4 deletions generic/pageObj.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ Cookfs_PageObj Cookfs_PageObjAlloc(Tcl_Size size) {
#ifdef TCL_THREADS
s->mx = NULL;
#endif /* TCL_THREADS */
#ifdef COOKFS_USECCRYPT
#ifdef COOKFS_USECCRYPTO
memset(s->IV, 0, COOKFS_PAGEOBJ_BLOCK_SIZE);
#endif /* COOKFS_USECCRYPT */
#endif /* COOKFS_USECCRYPTO */
p += sizeof(Cookfs_PageObjStruct);
}
CookfsLog(printf("Cookfs_PageObjAlloc: return %p", (void *)p));
Expand All @@ -89,7 +89,7 @@ Cookfs_PageObj Cookfs_PageObjNewFromByteArray(Tcl_Obj *obj) {
return rc;
}

#ifdef COOKFS_USECCRYPT
#ifdef COOKFS_USECCRYPTO

Cookfs_PageObj Cookfs_PageObjNewFromByteArrayIV(Tcl_Obj *obj) {
Tcl_Size size;
Expand Down Expand Up @@ -247,4 +247,4 @@ int Cookfs_PageObjRemovePadding(Cookfs_PageObj pg) {

}

#endif /* COOKFS_USECCRYPT */
#endif /* COOKFS_USECCRYPTO */
Loading

0 comments on commit ec15990

Please sign in to comment.