1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-15 01:04:37 +02:00

Rename cipher module to the more general crypto.

This commit is contained in:
David Steele
2018-06-11 10:53:16 -04:00
parent 835396751f
commit 064ec757e9
19 changed files with 294 additions and 253 deletions

View File

@ -29,6 +29,10 @@
<p>Auto-generate Makefile with dependencies.</p>
</release-item>
<release-item>
<p>Rename <code>cipher</code> module to the more general <code>crypto</code>.</p>
</release-item>
<release-item>
<p>Update Debian package to add debug symbols to <backrest/> executable.</p>
</release-item>

View File

@ -46,13 +46,13 @@ C includes
These includes are from the src directory. There is no Perl-specific code in them.
***********************************************************************************************************************************/
#include "cipher/random.h"
#include "common/error.h"
#include "common/lock.h"
#include "config/config.h"
#include "config/define.h"
#include "config/load.h"
#include "config/parse.h"
#include "crypto/random.h"
#include "perl/config.h"
#include "postgres/pageChecksum.h"
#include "storage/driver/posix/driver.h"
@ -67,7 +67,7 @@ XSH includes
These includes define data structures that are required for the C to Perl interface but are not part of the regular C source.
***********************************************************************************************************************************/
#include "xs/cipher/block.xsh"
#include "xs/crypto/cipherBlock.xsh"
#include "xs/common/encode.xsh"
/***********************************************************************************************************************************
@ -89,12 +89,12 @@ OUTPUT:
#
# These modules should map 1-1 with C modules in src directory.
# ----------------------------------------------------------------------------------------------------------------------------------
INCLUDE: xs/cipher/block.xs
INCLUDE: xs/cipher/random.xs
INCLUDE: xs/common/encode.xs
INCLUDE: xs/common/lock.xs
INCLUDE: xs/config/config.xs
INCLUDE: xs/config/configTest.xs
INCLUDE: xs/config/define.xs
INCLUDE: xs/crypto/cipherBlock.xs
INCLUDE: xs/crypto/random.xs
INCLUDE: xs/postgres/pageChecksum.xs
INCLUDE: xs/storage/storage.xs

View File

@ -31,9 +31,6 @@ my @stryCFile =
(
'LibC.c',
'cipher/block.c',
'cipher/cipher.c',
'cipher/random.c',
'command/command.c',
'common/debug.c',
'common/encode.c',
@ -60,6 +57,9 @@ my @stryCFile =
'config/define.c',
'config/load.c',
'config/parse.c',
'crypto/cipherBlock.c',
'crypto/crypto.c',
'crypto/random.c',
'perl/config.c',
'postgres/pageChecksum.c',
'storage/driver/posix/driver.c',

View File

@ -2,7 +2,7 @@
Block Cipher XS Header
***********************************************************************************************************************************/
#include "common/memContext.h"
#include "cipher/block.h"
#include "crypto/cipherBlock.h"
// Encrypt/decrypt modes
#define CIPHER_MODE_ENCRYPT ((int)cipherModeEncrypt)

View File

@ -54,9 +54,6 @@ DESTDIR =
# List of required source files. main.c should always be listed last and the rest in alpha order.
####################################################################################################################################
SRCS = \
cipher/block.c \
cipher/cipher.c \
cipher/random.c \
command/archive/common.c \
command/archive/get/get.c \
command/archive/push/push.c \
@ -89,6 +86,9 @@ SRCS = \
config/define.c \
config/load.c \
config/parse.c \
crypto/cipherBlock.c \
crypto/crypto.c \
crypto/random.c \
perl/config.c \
perl/exec.c \
postgres/info.c \
@ -122,15 +122,6 @@ install: pgbackrest
####################################################################################################################################
# Compile rules
####################################################################################################################################
cipher/block.o: cipher/block.c cipher/block.h cipher/cipher.h cipher/random.h common/debug.h common/error.auto.h common/error.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/type/convert.h
$(CC) $(CFLAGS) -c cipher/block.c -o cipher/block.o
cipher/cipher.o: cipher/cipher.c cipher/cipher.h common/debug.h common/log.h common/logLevel.h common/stackTrace.h common/type/convert.h
$(CC) $(CFLAGS) -c cipher/cipher.c -o cipher/cipher.o
cipher/random.o: cipher/random.c cipher/random.h common/debug.h common/error.auto.h common/error.h common/log.h common/logLevel.h common/stackTrace.h common/type/convert.h
$(CC) $(CFLAGS) -c cipher/random.c -o cipher/random.o
command/archive/common.o: command/archive/common.c command/archive/common.h common/assert.h common/debug.h common/error.auto.h common/error.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/stringList.h common/type/variant.h common/type/variantList.h common/wait.h postgres/version.h storage/driver/posix/driverRead.h storage/driver/posix/driverWrite.h storage/fileRead.h storage/fileWrite.h storage/helper.h storage/info.h storage/storage.h version.h
$(CC) $(CFLAGS) -c command/archive/common.c -o command/archive/common.o
@ -227,13 +218,22 @@ config/load.o: config/load.c command/command.h common/debug.h common/error.auto.
config/parse.o: config/parse.c common/assert.h common/debug.h common/error.auto.h common/error.h common/ini.h common/lock.h common/log.h common/logLevel.h common/memContext.h common/regExp.h common/stackTrace.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/stringList.h common/type/variant.h common/type/variantList.h config/config.auto.h config/config.h config/define.auto.h config/define.h config/parse.auto.c config/parse.h storage/driver/posix/driverRead.h storage/driver/posix/driverWrite.h storage/fileRead.h storage/fileWrite.h storage/helper.h storage/info.h storage/storage.h version.h
$(CC) $(CFLAGS) -c config/parse.c -o config/parse.o
crypto/cipherBlock.o: crypto/cipherBlock.c common/debug.h common/error.auto.h common/error.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/type/convert.h crypto/cipher.h crypto/cipherBlock.h crypto/crypto.h crypto/random.h
$(CC) $(CFLAGS) -c crypto/cipherBlock.c -o crypto/cipherBlock.o
crypto/crypto.o: crypto/crypto.c common/debug.h common/log.h common/logLevel.h common/stackTrace.h common/type/convert.h crypto/crypto.h
$(CC) $(CFLAGS) -c crypto/crypto.c -o crypto/crypto.o
crypto/random.o: crypto/random.c common/debug.h common/error.auto.h common/error.h common/log.h common/logLevel.h common/stackTrace.h common/type/convert.h crypto/random.h
$(CC) $(CFLAGS) -c crypto/random.c -o crypto/random.o
main.o: main.c command/archive/get/get.h command/archive/push/push.h command/command.h command/help/help.h common/debug.h common/error.auto.h common/error.h common/exit.h common/lock.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/stringList.h common/type/variant.h common/type/variantList.h config/config.auto.h config/config.h config/define.auto.h config/define.h config/load.h perl/exec.h version.h
$(CC) $(CFLAGS) -c main.c -o main.o
perl/config.o: perl/config.c common/debug.h common/error.auto.h common/error.h common/lock.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/stringList.h common/type/variant.h common/type/variantList.h config/config.auto.h config/config.h config/define.auto.h config/define.h
$(CC) $(CFLAGS) -c perl/config.c -o perl/config.o
perl/exec.o: perl/exec.c ../libc/LibC.h cipher/block.h cipher/cipher.h cipher/random.h common/debug.h common/encode.h common/error.auto.h common/error.h common/lock.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/stringList.h common/type/variant.h common/type/variantList.h config/config.auto.h config/config.h config/define.auto.h config/define.h config/load.h config/parse.h perl/config.h perl/embed.auto.c perl/exec.h perl/libc.auto.c postgres/pageChecksum.h storage/driver/posix/driver.h storage/driver/posix/driverRead.h storage/driver/posix/driverWrite.h storage/info.h version.h ../libc/xs/cipher/block.xsh ../libc/xs/common/encode.xsh
perl/exec.o: perl/exec.c ../libc/LibC.h common/debug.h common/encode.h common/error.auto.h common/error.h common/lock.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/stringList.h common/type/variant.h common/type/variantList.h config/config.auto.h config/config.h config/define.auto.h config/define.h config/load.h config/parse.h crypto/cipher.h crypto/cipherBlock.h crypto/random.h perl/config.h perl/embed.auto.c perl/exec.h perl/libc.auto.c postgres/pageChecksum.h storage/driver/posix/driver.h storage/driver/posix/driverRead.h storage/driver/posix/driverWrite.h storage/info.h version.h ../libc/xs/common/encode.xsh ../libc/xs/crypto/cipherBlock.xsh
$(CC) $(CFLAGS) -c perl/exec.c -o perl/exec.o
postgres/info.o: postgres/info.c common/debug.h common/error.auto.h common/error.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/stringList.h common/type/variant.h common/type/variantList.h postgres/info.h postgres/type.h postgres/version.h storage/driver/posix/driverRead.h storage/driver/posix/driverWrite.h storage/fileRead.h storage/fileWrite.h storage/helper.h storage/info.h storage/storage.h version.h

View File

@ -1,8 +1,8 @@
/***********************************************************************************************************************************
Cipher Header
***********************************************************************************************************************************/
#ifndef CIPHER_CIPHER_H
#define CIPHER_CIPHER_H
#ifndef CRYPTO_CIPHER_H
#define CRYPTO_CIPHER_H
#include <stdbool.h>
@ -15,10 +15,4 @@ typedef enum
cipherModeDecrypt,
} CipherMode;
/***********************************************************************************************************************************
Functions
***********************************************************************************************************************************/
void cipherInit();
bool cipherIsInit();
#endif

View File

@ -9,8 +9,9 @@ Block Cipher
#include "common/debug.h"
#include "common/log.h"
#include "common/memContext.h"
#include "cipher/block.h"
#include "cipher/random.h"
#include "crypto/cipherBlock.h"
#include "crypto/crypto.h"
#include "crypto/random.h"
/***********************************************************************************************************************************
Header constants and sizes
@ -60,8 +61,8 @@ cipherBlockNew(CipherMode mode, const char *cipherName, const unsigned char *pas
FUNCTION_DEBUG_END();
// Only need to init once.
if (!cipherIsInit())
cipherInit();
if (!cryptoIsInit())
cryptoInit();
// Lookup cipher by name. This means the ciphers passed in must exactly match a name expected by OpenSSL. This is a good
// thing since the name required by the openssl command-line tool will match what is used by pgBackRest.

View File

@ -1,15 +1,15 @@
/***********************************************************************************************************************************
Block Cipher Header
***********************************************************************************************************************************/
#ifndef CIPHER_BLOCK_H
#define CIPHER_BLOCK_H
#ifndef CRYPTO_CIPHERBLOCK_H
#define CRYPTO_CIPHERBLOCK_H
/***********************************************************************************************************************************
CipherBlock object
***********************************************************************************************************************************/
typedef struct CipherBlock CipherBlock;
#include "cipher/cipher.h"
#include "crypto/cipher.h"
/***********************************************************************************************************************************
Functions

View File

@ -1,33 +1,33 @@
/***********************************************************************************************************************************
Cipher General Init and Free
Crypto Common
***********************************************************************************************************************************/
#include <openssl/conf.h>
#include <openssl/evp.h>
#include <openssl/err.h>
#include "cipher/cipher.h"
#include "common/debug.h"
#include "common/log.h"
#include "crypto/crypto.h"
/***********************************************************************************************************************************
Flag to indicate if OpenSSL has already been initialized
***********************************************************************************************************************************/
static bool cipherInitDone = false;
static bool cryptoInitDone = false;
/***********************************************************************************************************************************
Initialize ciphers
***********************************************************************************************************************************/
void
cipherInit()
cryptoInit()
{
FUNCTION_DEBUG_VOID(logLevelTrace);
if (!cipherInitDone)
if (!cryptoInitDone)
{
ERR_load_crypto_strings();
OpenSSL_add_all_algorithms();
cipherInitDone = true;
cryptoInitDone = true;
}
FUNCTION_DEBUG_RESULT_VOID();
@ -37,8 +37,8 @@ cipherInit()
Have the ciphers been initialized?
***********************************************************************************************************************************/
bool
cipherIsInit()
cryptoIsInit()
{
FUNCTION_TEST_VOID();
FUNCTION_TEST_RESULT(BOOL, cipherInitDone);
FUNCTION_TEST_RESULT(BOOL, cryptoInitDone);
}

15
src/crypto/crypto.h Normal file
View File

@ -0,0 +1,15 @@
/***********************************************************************************************************************************
Crypto Common
***********************************************************************************************************************************/
#ifndef CRYPTO_CRYPTO_H
#define CRYPTO_CRYPTO_H
#include <stdbool.h>
/***********************************************************************************************************************************
Functions
***********************************************************************************************************************************/
void cryptoInit();
bool cryptoIsInit();
#endif

View File

@ -3,10 +3,10 @@ Cipher
***********************************************************************************************************************************/
#include <openssl/rand.h>
#include "cipher/random.h"
#include "common/debug.h"
#include "common/error.h"
#include "common/log.h"
#include "crypto/random.h"
/***********************************************************************************************************************************
Generate random bytes

View File

@ -1,8 +1,8 @@
/***********************************************************************************************************************************
Random Header
***********************************************************************************************************************************/
#ifndef CIPHER_RANDOM_H
#define CIPHER_RANDOM_H
#ifndef CRYPTO_RANDOM_H
#define CRYPTO_RANDOM_H
/***********************************************************************************************************************************
Functions

View File

@ -54,13 +54,13 @@ C includes
These includes are from the src directory. There is no Perl-specific code in them.
***********************************************************************************************************************************/
#include "cipher/random.h"
#include "common/error.h"
#include "common/lock.h"
#include "config/config.h"
#include "config/define.h"
#include "config/load.h"
#include "config/parse.h"
#include "crypto/random.h"
#include "perl/config.h"
#include "postgres/pageChecksum.h"
#include "storage/driver/posix/driver.h"
@ -75,7 +75,7 @@ XSH includes
These includes define data structures that are required for the C to Perl interface but are not part of the regular C source.
***********************************************************************************************************************************/
#include "xs/cipher/block.xsh"
#include "xs/crypto/cipherBlock.xsh"
#include "xs/common/encode.xsh"
/***********************************************************************************************************************************
@ -241,13 +241,7 @@ XS_EUPXS(XS_pgBackRest__LibC_libcUvSize)
}
/* INCLUDE: Including 'xs/cipher/block.xs' from 'LibC.xs' */
/* INCLUDE: Including 'xs/cipher/random.xs' from 'xs/cipher/block.xs' */
/* INCLUDE: Including 'xs/common/encode.xs' from 'xs/cipher/random.xs' */
/* INCLUDE: Including 'xs/common/encode.xs' from 'LibC.xs' */
/* INCLUDE: Including 'xs/common/lock.xs' from 'xs/common/encode.xs' */
@ -262,7 +256,13 @@ XS_EUPXS(XS_pgBackRest__LibC_libcUvSize)
/* INCLUDE: Including 'xs/config/define.xs' from 'xs/config/configTest.xs' */
/* INCLUDE: Including 'xs/postgres/pageChecksum.xs' from 'xs/config/define.xs' */
/* INCLUDE: Including 'xs/crypto/cipherBlock.xs' from 'xs/config/define.xs' */
/* INCLUDE: Including 'xs/crypto/random.xs' from 'xs/crypto/cipherBlock.xs' */
/* INCLUDE: Including 'xs/postgres/pageChecksum.xs' from 'xs/crypto/random.xs' */
/* INCLUDE: Including 'xs/storage/storage.xs' from 'xs/postgres/pageChecksum.xs' */
@ -389,7 +389,189 @@ XS_EUPXS(XS_pgBackRest__LibC_pageChecksumBufferTest)
}
/* INCLUDE: Returning to 'xs/config/define.xs' from 'xs/postgres/pageChecksum.xs' */
/* INCLUDE: Returning to 'xs/crypto/random.xs' from 'xs/postgres/pageChecksum.xs' */
XS_EUPXS(XS_pgBackRest__LibC_randomBytes); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_pgBackRest__LibC_randomBytes)
{
dVAR; dXSARGS;
if (items != 1)
croak_xs_usage(cv, "size");
{
I32 size = (I32)SvIV(ST(0))
;
SV * RETVAL;
RETVAL = newSV(size);
SvPOK_only(RETVAL);
randomBytes((unsigned char *)SvPV_nolen(RETVAL), size);
SvCUR_set(RETVAL, size);
RETVAL = sv_2mortal(RETVAL);
ST(0) = RETVAL;
}
XSRETURN(1);
}
/* INCLUDE: Returning to 'xs/crypto/cipherBlock.xs' from 'xs/crypto/random.xs' */
XS_EUPXS(XS_pgBackRest__LibC__Cipher__Block_new); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_pgBackRest__LibC__Cipher__Block_new)
{
dVAR; dXSARGS;
if (items < 5 || items > 6)
croak_xs_usage(cv, "class, mode, type, key, keySize, digest = NULL");
{
const char * class = (const char *)SvPV_nolen(ST(0))
;
U32 mode = (unsigned long)SvUV(ST(1))
;
const char * type = (const char *)SvPV_nolen(ST(2))
;
unsigned char * key = (unsigned char *)SvPV_nolen(ST(3))
;
I32 keySize = (I32)SvIV(ST(4))
;
const char * digest;
pgBackRest__LibC__Cipher__Block RETVAL;
if (items < 6)
digest = NULL;
else {
digest = (const char *)SvPV_nolen(ST(5))
;
}
RETVAL = NULL;
// Not much point to this but it keeps the var from being unused
if (strcmp(class, PACKAGE_NAME_LIBC "::Cipher::Block") != 0)
croak("unexpected class name '%s'", class);
MEM_CONTEXT_XS_NEW_BEGIN("cipherBlockXs")
{
RETVAL = memNew(sizeof(CipherBlockXs));
RETVAL->memContext = MEM_COMTEXT_XS();
RETVAL->pxPayload = cipherBlockNew(mode, type, key, keySize, digest);
}
MEM_CONTEXT_XS_NEW_END();
{
SV * RETVALSV;
RETVALSV = sv_newmortal();
sv_setref_pv(RETVALSV, "pgBackRest::LibC::Cipher::Block", (void*)RETVAL);
ST(0) = RETVALSV;
}
}
XSRETURN(1);
}
XS_EUPXS(XS_pgBackRest__LibC__Cipher__Block_process); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_pgBackRest__LibC__Cipher__Block_process)
{
dVAR; dXSARGS;
if (items != 2)
croak_xs_usage(cv, "self, source");
{
pgBackRest__LibC__Cipher__Block self;
SV * source = ST(1)
;
SV * RETVAL;
if (SvROK(ST(0)) && sv_derived_from(ST(0), "pgBackRest::LibC::Cipher::Block")) {
IV tmp = SvIV((SV*)SvRV(ST(0)));
self = INT2PTR(pgBackRest__LibC__Cipher__Block,tmp);
}
else
Perl_croak_nocontext("%s: %s is not of type %s",
"pgBackRest::LibC::Cipher::Block::process",
"self", "pgBackRest::LibC::Cipher::Block")
;
RETVAL = NULL;
MEM_CONTEXT_XS_BEGIN(self->memContext)
{
STRLEN tSize;
const unsigned char *sourcePtr = (const unsigned char *)SvPV(source, tSize);
RETVAL = NEWSV(0, cipherBlockProcessSize(self->pxPayload, tSize));
SvPOK_only(RETVAL);
SvCUR_set(RETVAL, cipherBlockProcess(self->pxPayload, sourcePtr, tSize, (unsigned char *)SvPV_nolen(RETVAL)));
}
MEM_CONTEXT_XS_END();
RETVAL = sv_2mortal(RETVAL);
ST(0) = RETVAL;
}
XSRETURN(1);
}
XS_EUPXS(XS_pgBackRest__LibC__Cipher__Block_flush); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_pgBackRest__LibC__Cipher__Block_flush)
{
dVAR; dXSARGS;
if (items != 1)
croak_xs_usage(cv, "self");
{
pgBackRest__LibC__Cipher__Block self;
SV * RETVAL;
if (SvROK(ST(0)) && sv_derived_from(ST(0), "pgBackRest::LibC::Cipher::Block")) {
IV tmp = SvIV((SV*)SvRV(ST(0)));
self = INT2PTR(pgBackRest__LibC__Cipher__Block,tmp);
}
else
Perl_croak_nocontext("%s: %s is not of type %s",
"pgBackRest::LibC::Cipher::Block::flush",
"self", "pgBackRest::LibC::Cipher::Block")
;
RETVAL = NULL;
MEM_CONTEXT_XS_BEGIN(self->memContext)
{
RETVAL = NEWSV(0, cipherBlockProcessSize(self->pxPayload, 0));
SvPOK_only(RETVAL);
SvCUR_set(RETVAL, cipherBlockFlush(self->pxPayload, (unsigned char *)SvPV_nolen(RETVAL)));
}
MEM_CONTEXT_XS_END();
RETVAL = sv_2mortal(RETVAL);
ST(0) = RETVAL;
}
XSRETURN(1);
}
XS_EUPXS(XS_pgBackRest__LibC__Cipher__Block_DESTROY); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_pgBackRest__LibC__Cipher__Block_DESTROY)
{
dVAR; dXSARGS;
if (items != 1)
croak_xs_usage(cv, "self");
{
pgBackRest__LibC__Cipher__Block self;
if (SvROK(ST(0))) {
IV tmp = SvIV((SV*)SvRV(ST(0)));
self = INT2PTR(pgBackRest__LibC__Cipher__Block,tmp);
}
else
Perl_croak_nocontext("%s: %s is not a reference",
"pgBackRest::LibC::Cipher::Block::DESTROY",
"self")
;
MEM_CONTEXT_XS_DESTROY(self->memContext);
}
XSRETURN_EMPTY;
}
/* INCLUDE: Returning to 'xs/config/define.xs' from 'xs/crypto/cipherBlock.xs' */
XS_EUPXS(XS_pgBackRest__LibC_cfgCommandId); /* prototype to pass -Wmissing-prototypes */
@ -829,189 +1011,7 @@ XS_EUPXS(XS_pgBackRest__LibC_decodeToBin)
}
/* INCLUDE: Returning to 'xs/cipher/random.xs' from 'xs/common/encode.xs' */
XS_EUPXS(XS_pgBackRest__LibC_randomBytes); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_pgBackRest__LibC_randomBytes)
{
dVAR; dXSARGS;
if (items != 1)
croak_xs_usage(cv, "size");
{
I32 size = (I32)SvIV(ST(0))
;
SV * RETVAL;
RETVAL = newSV(size);
SvPOK_only(RETVAL);
randomBytes((unsigned char *)SvPV_nolen(RETVAL), size);
SvCUR_set(RETVAL, size);
RETVAL = sv_2mortal(RETVAL);
ST(0) = RETVAL;
}
XSRETURN(1);
}
/* INCLUDE: Returning to 'xs/cipher/block.xs' from 'xs/cipher/random.xs' */
XS_EUPXS(XS_pgBackRest__LibC__Cipher__Block_new); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_pgBackRest__LibC__Cipher__Block_new)
{
dVAR; dXSARGS;
if (items < 5 || items > 6)
croak_xs_usage(cv, "class, mode, type, key, keySize, digest = NULL");
{
const char * class = (const char *)SvPV_nolen(ST(0))
;
U32 mode = (unsigned long)SvUV(ST(1))
;
const char * type = (const char *)SvPV_nolen(ST(2))
;
unsigned char * key = (unsigned char *)SvPV_nolen(ST(3))
;
I32 keySize = (I32)SvIV(ST(4))
;
const char * digest;
pgBackRest__LibC__Cipher__Block RETVAL;
if (items < 6)
digest = NULL;
else {
digest = (const char *)SvPV_nolen(ST(5))
;
}
RETVAL = NULL;
// Not much point to this but it keeps the var from being unused
if (strcmp(class, PACKAGE_NAME_LIBC "::Cipher::Block") != 0)
croak("unexpected class name '%s'", class);
MEM_CONTEXT_XS_NEW_BEGIN("cipherBlockXs")
{
RETVAL = memNew(sizeof(CipherBlockXs));
RETVAL->memContext = MEM_COMTEXT_XS();
RETVAL->pxPayload = cipherBlockNew(mode, type, key, keySize, digest);
}
MEM_CONTEXT_XS_NEW_END();
{
SV * RETVALSV;
RETVALSV = sv_newmortal();
sv_setref_pv(RETVALSV, "pgBackRest::LibC::Cipher::Block", (void*)RETVAL);
ST(0) = RETVALSV;
}
}
XSRETURN(1);
}
XS_EUPXS(XS_pgBackRest__LibC__Cipher__Block_process); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_pgBackRest__LibC__Cipher__Block_process)
{
dVAR; dXSARGS;
if (items != 2)
croak_xs_usage(cv, "self, source");
{
pgBackRest__LibC__Cipher__Block self;
SV * source = ST(1)
;
SV * RETVAL;
if (SvROK(ST(0)) && sv_derived_from(ST(0), "pgBackRest::LibC::Cipher::Block")) {
IV tmp = SvIV((SV*)SvRV(ST(0)));
self = INT2PTR(pgBackRest__LibC__Cipher__Block,tmp);
}
else
Perl_croak_nocontext("%s: %s is not of type %s",
"pgBackRest::LibC::Cipher::Block::process",
"self", "pgBackRest::LibC::Cipher::Block")
;
RETVAL = NULL;
MEM_CONTEXT_XS_BEGIN(self->memContext)
{
STRLEN tSize;
const unsigned char *sourcePtr = (const unsigned char *)SvPV(source, tSize);
RETVAL = NEWSV(0, cipherBlockProcessSize(self->pxPayload, tSize));
SvPOK_only(RETVAL);
SvCUR_set(RETVAL, cipherBlockProcess(self->pxPayload, sourcePtr, tSize, (unsigned char *)SvPV_nolen(RETVAL)));
}
MEM_CONTEXT_XS_END();
RETVAL = sv_2mortal(RETVAL);
ST(0) = RETVAL;
}
XSRETURN(1);
}
XS_EUPXS(XS_pgBackRest__LibC__Cipher__Block_flush); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_pgBackRest__LibC__Cipher__Block_flush)
{
dVAR; dXSARGS;
if (items != 1)
croak_xs_usage(cv, "self");
{
pgBackRest__LibC__Cipher__Block self;
SV * RETVAL;
if (SvROK(ST(0)) && sv_derived_from(ST(0), "pgBackRest::LibC::Cipher::Block")) {
IV tmp = SvIV((SV*)SvRV(ST(0)));
self = INT2PTR(pgBackRest__LibC__Cipher__Block,tmp);
}
else
Perl_croak_nocontext("%s: %s is not of type %s",
"pgBackRest::LibC::Cipher::Block::flush",
"self", "pgBackRest::LibC::Cipher::Block")
;
RETVAL = NULL;
MEM_CONTEXT_XS_BEGIN(self->memContext)
{
RETVAL = NEWSV(0, cipherBlockProcessSize(self->pxPayload, 0));
SvPOK_only(RETVAL);
SvCUR_set(RETVAL, cipherBlockFlush(self->pxPayload, (unsigned char *)SvPV_nolen(RETVAL)));
}
MEM_CONTEXT_XS_END();
RETVAL = sv_2mortal(RETVAL);
ST(0) = RETVAL;
}
XSRETURN(1);
}
XS_EUPXS(XS_pgBackRest__LibC__Cipher__Block_DESTROY); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_pgBackRest__LibC__Cipher__Block_DESTROY)
{
dVAR; dXSARGS;
if (items != 1)
croak_xs_usage(cv, "self");
{
pgBackRest__LibC__Cipher__Block self;
if (SvROK(ST(0))) {
IV tmp = SvIV((SV*)SvRV(ST(0)));
self = INT2PTR(pgBackRest__LibC__Cipher__Block,tmp);
}
else
Perl_croak_nocontext("%s: %s is not a reference",
"pgBackRest::LibC::Cipher::Block::DESTROY",
"self")
;
MEM_CONTEXT_XS_DESTROY(self->memContext);
}
XSRETURN_EMPTY;
}
/* INCLUDE: Returning to 'LibC.xs' from 'xs/cipher/block.xs' */
/* INCLUDE: Returning to 'LibC.xs' from 'xs/common/encode.xs' */
#ifdef __cplusplus
extern "C"
@ -1046,6 +1046,11 @@ XS_EXTERNAL(boot_pgBackRest__LibC)
newXS_deffile("pgBackRest::LibC::pageChecksum", XS_pgBackRest__LibC_pageChecksum);
newXS_deffile("pgBackRest::LibC::pageChecksumTest", XS_pgBackRest__LibC_pageChecksumTest);
newXS_deffile("pgBackRest::LibC::pageChecksumBufferTest", XS_pgBackRest__LibC_pageChecksumBufferTest);
newXS_deffile("pgBackRest::LibC::randomBytes", XS_pgBackRest__LibC_randomBytes);
newXS_deffile("pgBackRest::LibC::Cipher::Block::new", XS_pgBackRest__LibC__Cipher__Block_new);
newXS_deffile("pgBackRest::LibC::Cipher::Block::process", XS_pgBackRest__LibC__Cipher__Block_process);
newXS_deffile("pgBackRest::LibC::Cipher::Block::flush", XS_pgBackRest__LibC__Cipher__Block_flush);
newXS_deffile("pgBackRest::LibC::Cipher::Block::DESTROY", XS_pgBackRest__LibC__Cipher__Block_DESTROY);
newXS_deffile("pgBackRest::LibC::cfgCommandId", XS_pgBackRest__LibC_cfgCommandId);
newXS_deffile("pgBackRest::LibC::cfgOptionId", XS_pgBackRest__LibC_cfgOptionId);
newXS_deffile("pgBackRest::LibC::cfgDefOptionDefault", XS_pgBackRest__LibC_cfgDefOptionDefault);
@ -1063,11 +1068,6 @@ XS_EXTERNAL(boot_pgBackRest__LibC)
newXS_deffile("pgBackRest::LibC::lockRelease", XS_pgBackRest__LibC_lockRelease);
newXS_deffile("pgBackRest::LibC::encodeToStr", XS_pgBackRest__LibC_encodeToStr);
newXS_deffile("pgBackRest::LibC::decodeToBin", XS_pgBackRest__LibC_decodeToBin);
newXS_deffile("pgBackRest::LibC::randomBytes", XS_pgBackRest__LibC_randomBytes);
newXS_deffile("pgBackRest::LibC::Cipher::Block::new", XS_pgBackRest__LibC__Cipher__Block_new);
newXS_deffile("pgBackRest::LibC::Cipher::Block::process", XS_pgBackRest__LibC__Cipher__Block_process);
newXS_deffile("pgBackRest::LibC::Cipher::Block::flush", XS_pgBackRest__LibC__Cipher__Block_flush);
newXS_deffile("pgBackRest::LibC::Cipher::Block::DESTROY", XS_pgBackRest__LibC__Cipher__Block_DESTROY);
#if PERL_VERSION_LE(5, 21, 5)
# if PERL_VERSION_GE(5, 9, 0)
if (PL_unitcheckav)

View File

@ -268,22 +268,29 @@ unit:
Common/Log: partial
# ********************************************************************************************************************************
- name: cipher
- name: crypto
test:
# ----------------------------------------------------------------------------------------------------------------------------
- name: crypto
total: 1
coverage:
crypto/crypto: full
# ----------------------------------------------------------------------------------------------------------------------------
- name: random
total: 1
coverage:
cipher/random: full
crypto/random: full
# ----------------------------------------------------------------------------------------------------------------------------
- name: block
- name: cipherBlock
total: 2
coverage:
cipher/block: full
crypto/cipherBlock: full
# ********************************************************************************************************************************
- name: postgres

View File

@ -1,9 +1,6 @@
/***********************************************************************************************************************************
Test Block Cipher
***********************************************************************************************************************************/
#include <openssl/evp.h>
#include "cipher/cipher.h"
/***********************************************************************************************************************************
Data for testing

View File

@ -0,0 +1,23 @@
/***********************************************************************************************************************************
Test Crypto Common
***********************************************************************************************************************************/
/***********************************************************************************************************************************
Test Run
***********************************************************************************************************************************/
void
testRun()
{
FUNCTION_HARNESS_VOID();
// -----------------------------------------------------------------------------------------------------------------------------
if (testBegin("cryptoInit() and cryptoIsInit()"))
{
TEST_RESULT_BOOL(cryptoIsInit(), false, "crypto is not initialized");
TEST_RESULT_VOID(cryptoInit(), "initialize crypto");
TEST_RESULT_BOOL(cryptoIsInit(), true, "crypto is initialized");
TEST_RESULT_VOID(cryptoInit(), "initialize crypto again");
}
FUNCTION_HARNESS_RESULT_VOID();
}