gwenhywfar 5.12.0
cryptkeyrsa.c File Reference
#include "cryptkeyrsa_p.h"
#include <gwenhywfar/misc.h>
#include <gwenhywfar/debug.h>
#include <gwenhywfar/text.h>
Include dependency graph for cryptkeyrsa.c:

Go to the source code of this file.

Macros

#define DISABLE_DEBUGLOG
#define PRI_SIZET   "zd"

Functions

static int GWEN_Crypt_KeyRsa__getNamedElement (gcry_sexp_t pkey, const char *name, gcry_mpi_t *pMpi)
static int GWEN_Crypt_KeyRsa__MpiToBuffer (const gcry_mpi_t mpi, unsigned char *buf, size_t nbytes)
static int GWEN_Crypt_KeyRsa__ReadMpi (GWEN_DB_NODE *db, const char *dbName, gcry_mpi_t *pMpi)
static int GWEN_Crypt_KeyRsa__WriteMpi (GWEN_DB_NODE *db, const char *dbName, const gcry_mpi_t mpi)
void GWEN_Crypt_KeyRsa_AddFlags (GWEN_CRYPT_KEY *k, uint32_t fl)
static GWENHYWFAR_CB int GWEN_Crypt_KeyRsa_Decipher (GWEN_CRYPT_KEY *k, const uint8_t *pInData, uint32_t inLen, uint8_t *pOutData, uint32_t *pOutLen)
GWEN_CRYPT_KEYGWEN_Crypt_KeyRsa_dup (const GWEN_CRYPT_KEY *k)
static GWENHYWFAR_CB int GWEN_Crypt_KeyRsa_Encipher (GWEN_CRYPT_KEY *k, const uint8_t *pInData, uint32_t inLen, uint8_t *pOutData, uint32_t *pOutLen)
static GWENHYWFAR_CB void GWEN_Crypt_KeyRsa_freeData (GWEN_UNUSED void *bp, void *p)
GWEN_CRYPT_KEYGWEN_Crypt_KeyRsa_fromDb (GWEN_DB_NODE *db)
GWEN_CRYPT_KEYGWEN_Crypt_KeyRsa_fromModExp (unsigned int nbytes, const uint8_t *pModulus, uint32_t lModulus, const uint8_t *pExponent, uint32_t lExponent)
GWEN_CRYPT_KEYGWEN_Crypt_KeyRsa_fromModPrivExp (unsigned int nbytes, const uint8_t *pModulus, uint32_t lModulus, const uint8_t *pExponent, uint32_t lExponent, const uint8_t *pPrivExponent, uint32_t lPrivExponent)
int GWEN_Crypt_KeyRsa_GeneratePair (unsigned int nbytes, int use65537e, GWEN_CRYPT_KEY **pPubKey, GWEN_CRYPT_KEY **pSecretKey)
int GWEN_Crypt_KeyRsa_GeneratePair2 (unsigned int nbits, int use65537e, GWEN_CRYPT_KEY **pPubKey, GWEN_CRYPT_KEY **pSecretKey)
int GWEN_Crypt_KeyRsa_GetExponent (const GWEN_CRYPT_KEY *k, uint8_t *buffer, uint32_t *pBufLen)
uint32_t GWEN_Crypt_KeyRsa_GetFlags (const GWEN_CRYPT_KEY *k)
int GWEN_Crypt_KeyRsa_GetModulus (const GWEN_CRYPT_KEY *k, uint8_t *buffer, uint32_t *pBufLen)
int GWEN_Crypt_KeyRsa_GetSecretExponent (const GWEN_CRYPT_KEY *k, uint8_t *buffer, uint32_t *pBufLen)
void GWEN_Crypt_KeyRsa_SetFlags (GWEN_CRYPT_KEY *k, uint32_t fl)
GWENHYWFAR_CB int GWEN_Crypt_KeyRsa_Sign (GWEN_CRYPT_KEY *k, const uint8_t *pInData, uint32_t inLen, uint8_t *pSignatureData, uint32_t *pSignatureLen)
void GWEN_Crypt_KeyRsa_SubFlags (GWEN_CRYPT_KEY *k, uint32_t fl)
int GWEN_Crypt_KeyRsa_toDb (const GWEN_CRYPT_KEY *k, GWEN_DB_NODE *db, int pub)
static GWENHYWFAR_CB int GWEN_Crypt_KeyRsa_Verify (GWEN_CRYPT_KEY *k, const uint8_t *pInData, uint32_t inLen, const uint8_t *pSignatureData, uint32_t signatureLen)

Macro Definition Documentation

◆ DISABLE_DEBUGLOG

#define DISABLE_DEBUGLOG

Definition at line 14 of file cryptkeyrsa.c.

◆ PRI_SIZET

#define PRI_SIZET   "zd"

Definition at line 99 of file cryptkeyrsa.c.

Referenced by GWEN_Crypt_KeyRsa_GeneratePair(), and GWEN_DBIO_OldDb__ParseLine().

Function Documentation

◆ GWEN_Crypt_KeyRsa__getNamedElement()

int GWEN_Crypt_KeyRsa__getNamedElement ( gcry_sexp_t pkey,
const char * name,
gcry_mpi_t * pMpi )
static

Definition at line 62 of file cryptkeyrsa.c.

References DBG_ERROR, GWEN_ERROR_GENERIC, and GWEN_LOGDOMAIN.

Referenced by GWEN_Crypt_KeyRsa_GeneratePair().

Here is the caller graph for this function:

◆ GWEN_Crypt_KeyRsa__MpiToBuffer()

int GWEN_Crypt_KeyRsa__MpiToBuffer ( const gcry_mpi_t mpi,
unsigned char * buf,
size_t nbytes )
static

Definition at line 613 of file cryptkeyrsa.c.

References DBG_INFO, GWEN_ERROR_GENERIC, and GWEN_LOGDOMAIN.

Referenced by GWEN_Crypt_KeyRsa_GetExponent(), GWEN_Crypt_KeyRsa_GetModulus(), and GWEN_Crypt_KeyRsa_GetSecretExponent().

Here is the caller graph for this function:

◆ GWEN_Crypt_KeyRsa__ReadMpi()

int GWEN_Crypt_KeyRsa__ReadMpi ( GWEN_DB_NODE * db,
const char * dbName,
gcry_mpi_t * pMpi )
static

Definition at line 556 of file cryptkeyrsa.c.

References DBG_INFO, GWEN_DB_GetBinValue(), GWEN_ERROR_BAD_DATA, GWEN_ERROR_GENERIC, GWEN_ERROR_NO_DATA, GWEN_LOGDOMAIN, and NULL.

Referenced by GWEN_Crypt_KeyRsa_fromDb().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GWEN_Crypt_KeyRsa__WriteMpi()

int GWEN_Crypt_KeyRsa__WriteMpi ( GWEN_DB_NODE * db,
const char * dbName,
const gcry_mpi_t mpi )
static

Definition at line 591 of file cryptkeyrsa.c.

References DBG_INFO, GWEN_DB_FLAGS_OVERWRITE_VARS, GWEN_DB_SetBinValue(), GWEN_ERROR_GENERIC, and GWEN_LOGDOMAIN.

Referenced by GWEN_Crypt_KeyRsa_toDb().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GWEN_Crypt_KeyRsa_AddFlags()

void GWEN_Crypt_KeyRsa_AddFlags ( GWEN_CRYPT_KEY * k,
uint32_t fl )

Definition at line 1018 of file cryptkeyrsa.c.

References GWEN_INHERIT_GETDATA.

Referenced by GWEN_Crypt_TokenFile__ActivateKey(), GWEN_Crypt_TokenFile__GenerateKey(), GWEN_Crypt_TokenOHBCI__Decode(), signArchive(), and verifyArchive().

Here is the caller graph for this function:

◆ GWEN_Crypt_KeyRsa_Decipher()

GWENHYWFAR_CB int GWEN_Crypt_KeyRsa_Decipher ( GWEN_CRYPT_KEY * k,
const uint8_t * pInData,
uint32_t inLen,
uint8_t * pOutData,
uint32_t * pOutLen )
static

Definition at line 497 of file cryptkeyrsa.c.

References DBG_ERROR, DBG_INFO, GWEN_Crypt_Key_GetKeySize(), GWEN_ERROR_BAD_DATA, GWEN_INHERIT_GETDATA, GWEN_LOGDOMAIN, GWENHYWFAR_CB, and NULL.

Referenced by GWEN_Crypt_KeyRsa_fromDb(), and GWEN_Crypt_KeyRsa_GeneratePair().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GWEN_Crypt_KeyRsa_dup()

GWEN_CRYPT_KEY * GWEN_Crypt_KeyRsa_dup ( const GWEN_CRYPT_KEY * k)

Definition at line 960 of file cryptkeyrsa.c.

References DBG_INFO, GWEN_Crypt_KeyRsa_fromDb(), GWEN_Crypt_KeyRsa_SetFlags(), GWEN_Crypt_KeyRsa_toDb(), GWEN_DB_Group_free(), GWEN_DB_Group_new(), GWEN_INHERIT_GETDATA, GWEN_LOGDOMAIN, and NULL.

Referenced by GWEN_Crypt_TokenFile__ActivateKey().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GWEN_Crypt_KeyRsa_Encipher()

GWENHYWFAR_CB int GWEN_Crypt_KeyRsa_Encipher ( GWEN_CRYPT_KEY * k,
const uint8_t * pInData,
uint32_t inLen,
uint8_t * pOutData,
uint32_t * pOutLen )
static

Definition at line 438 of file cryptkeyrsa.c.

References DBG_ERROR, DBG_INFO, GWEN_Crypt_Key_GetKeySize(), GWEN_ERROR_BAD_DATA, GWEN_INHERIT_GETDATA, GWEN_LOGDOMAIN, GWENHYWFAR_CB, and NULL.

Referenced by GWEN_Crypt_KeyRsa_fromDb(), and GWEN_Crypt_KeyRsa_GeneratePair().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GWEN_Crypt_KeyRsa_freeData()

GWENHYWFAR_CB void GWEN_Crypt_KeyRsa_freeData ( GWEN_UNUSED void * bp,
void * p )
static

Definition at line 631 of file cryptkeyrsa.c.

References GWEN_FREE_OBJECT, and GWEN_UNUSED.

Referenced by GWEN_Crypt_KeyRsa_fromDb(), and GWEN_Crypt_KeyRsa_GeneratePair().

Here is the caller graph for this function:

◆ GWEN_Crypt_KeyRsa_fromDb()

◆ GWEN_Crypt_KeyRsa_fromModExp()

GWEN_CRYPT_KEY * GWEN_Crypt_KeyRsa_fromModExp ( unsigned int nbytes,
const uint8_t * pModulus,
uint32_t lModulus,
const uint8_t * pExponent,
uint32_t lExponent )

◆ GWEN_Crypt_KeyRsa_fromModPrivExp()

GWEN_CRYPT_KEY * GWEN_Crypt_KeyRsa_fromModPrivExp ( unsigned int nbytes,
const uint8_t * pModulus,
uint32_t lModulus,
const uint8_t * pExponent,
uint32_t lExponent,
const uint8_t * pPrivExponent,
uint32_t lPrivExponent )

◆ GWEN_Crypt_KeyRsa_GeneratePair()

int GWEN_Crypt_KeyRsa_GeneratePair ( unsigned int nbytes,
int use65537e,
GWEN_CRYPT_KEY ** pPubKey,
GWEN_CRYPT_KEY ** pSecretKey )

Creates a key pair and returns a pointer to it.

Returns
NULL on error, otherwise a pointer to two keys: public and private
Parameters
nbytesnumber of bytes
use65537e!=0: use the value 65537 for the public exponent, otherwise let the library choose the exponent by its own

Definition at line 103 of file cryptkeyrsa.c.

References DBG_ERROR, DBG_INFO, GWEN_Crypt_Key_new(), GWEN_Crypt_Key_SetDecipherFn(), GWEN_Crypt_Key_SetEncipherFn(), GWEN_Crypt_Key_SetSignFn(), GWEN_Crypt_Key_SetVerifyFn(), GWEN_Crypt_KeyRsa__getNamedElement(), GWEN_Crypt_KeyRsa_Decipher(), GWEN_Crypt_KeyRsa_Encipher(), GWEN_Crypt_KeyRsa_freeData(), GWEN_Crypt_KeyRsa_Sign(), GWEN_Crypt_KeyRsa_Verify(), GWEN_ERROR_GENERIC, GWEN_INHERIT_SETDATA, GWEN_LOGDOMAIN, GWEN_NEW_OBJECT, NULL, and PRI_SIZET.

Referenced by GWEN_Crypt_KeyRsa_GeneratePair2(), GWEN_Crypt_TokenFile__GenerateKey(), and mkArchiveKey().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GWEN_Crypt_KeyRsa_GeneratePair2()

int GWEN_Crypt_KeyRsa_GeneratePair2 ( unsigned int nbits,
int use65537e,
GWEN_CRYPT_KEY ** pPubKey,
GWEN_CRYPT_KEY ** pSecretKey )

Creates a key pair and returns a pointer to it. This function allows for more precise control over the size of the created key because it lets you specify the size in bits rather than in bytes.

Returns
NULL on error, otherwise a pointer to two keys: public and private
Parameters
nbitsnumber of bits
use65537e!=0: use the value 65537 for the public exponent, otherwise let the library choose the exponent by its own
Deprecated
Please use GWEN_Crypt_KeyRsa_GeneratePair instead since nbits should be a multiple of 8 anyway according to Libgcrypt.

Definition at line 272 of file cryptkeyrsa.c.

References DBG_ERROR, GWEN_Crypt_KeyRsa_GeneratePair(), GWEN_ERROR_INVALID, and GWEN_LOGDOMAIN.

Here is the call graph for this function:

◆ GWEN_Crypt_KeyRsa_GetExponent()

int GWEN_Crypt_KeyRsa_GetExponent ( const GWEN_CRYPT_KEY * k,
uint8_t * buffer,
uint32_t * pBufLen )

Definition at line 803 of file cryptkeyrsa.c.

References DBG_INFO, GWEN_Crypt_KeyRsa__MpiToBuffer(), GWEN_ERROR_GENERIC, GWEN_INHERIT_GETDATA, and GWEN_LOGDOMAIN.

Referenced by GWEN_Crypt_TokenFile__ActivateKey(), GWEN_Crypt_TokenFile__GenerateKey(), and GWEN_Crypt_TokenOHBCI__Decode().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GWEN_Crypt_KeyRsa_GetFlags()

uint32_t GWEN_Crypt_KeyRsa_GetFlags ( const GWEN_CRYPT_KEY * k)

Definition at line 992 of file cryptkeyrsa.c.

References GWEN_INHERIT_GETDATA.

◆ GWEN_Crypt_KeyRsa_GetModulus()

int GWEN_Crypt_KeyRsa_GetModulus ( const GWEN_CRYPT_KEY * k,
uint8_t * buffer,
uint32_t * pBufLen )

Definition at line 780 of file cryptkeyrsa.c.

References DBG_INFO, GWEN_Crypt_KeyRsa__MpiToBuffer(), GWEN_ERROR_GENERIC, GWEN_INHERIT_GETDATA, and GWEN_LOGDOMAIN.

Referenced by GWEN_Crypt_TokenFile__ActivateKey(), GWEN_Crypt_TokenFile__GenerateKey(), and GWEN_Crypt_TokenOHBCI__Decode().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GWEN_Crypt_KeyRsa_GetSecretExponent()

int GWEN_Crypt_KeyRsa_GetSecretExponent ( const GWEN_CRYPT_KEY * k,
uint8_t * buffer,
uint32_t * pBufLen )

Definition at line 826 of file cryptkeyrsa.c.

References DBG_INFO, GWEN_Crypt_KeyRsa__MpiToBuffer(), GWEN_ERROR_GENERIC, GWEN_INHERIT_GETDATA, and GWEN_LOGDOMAIN.

Here is the call graph for this function:

◆ GWEN_Crypt_KeyRsa_SetFlags()

void GWEN_Crypt_KeyRsa_SetFlags ( GWEN_CRYPT_KEY * k,
uint32_t fl )

Definition at line 1005 of file cryptkeyrsa.c.

References GWEN_INHERIT_GETDATA.

Referenced by GWEN_Crypt_KeyRsa_dup().

Here is the caller graph for this function:

◆ GWEN_Crypt_KeyRsa_Sign()

GWENHYWFAR_CB int GWEN_Crypt_KeyRsa_Sign ( GWEN_CRYPT_KEY * k,
const uint8_t * pInData,
uint32_t inLen,
uint8_t * pSignatureData,
uint32_t * pSignatureLen )

Definition at line 288 of file cryptkeyrsa.c.

References DBG_DEBUG, DBG_ERROR, DBG_INFO, GWEN_Crypt_Key_GetKeySize(), GWEN_CRYPT_KEYRSA_FLAGS_DIRECTSIGN, GWEN_ERROR_BAD_DATA, GWEN_INHERIT_GETDATA, GWEN_LOGDOMAIN, GWENHYWFAR_CB, and NULL.

Referenced by GWEN_Crypt_KeyRsa_fromDb(), and GWEN_Crypt_KeyRsa_GeneratePair().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GWEN_Crypt_KeyRsa_SubFlags()

void GWEN_Crypt_KeyRsa_SubFlags ( GWEN_CRYPT_KEY * k,
uint32_t fl )

Definition at line 1031 of file cryptkeyrsa.c.

References GWEN_INHERIT_GETDATA.

◆ GWEN_Crypt_KeyRsa_toDb()

int GWEN_Crypt_KeyRsa_toDb ( const GWEN_CRYPT_KEY * k,
GWEN_DB_NODE * db,
int pub )

◆ GWEN_Crypt_KeyRsa_Verify()

GWENHYWFAR_CB int GWEN_Crypt_KeyRsa_Verify ( GWEN_CRYPT_KEY * k,
const uint8_t * pInData,
uint32_t inLen,
const uint8_t * pSignatureData,
uint32_t signatureLen )
static

Definition at line 359 of file cryptkeyrsa.c.

References DBG_DEBUG, DBG_ERROR, DBG_INFO, GWEN_Crypt_Key_GetKeySize(), GWEN_ERROR_BAD_DATA, GWEN_ERROR_VERIFY, GWEN_INHERIT_GETDATA, GWEN_LOGDOMAIN, GWENHYWFAR_CB, and NULL.

Referenced by GWEN_Crypt_KeyRsa_fromDb(), and GWEN_Crypt_KeyRsa_GeneratePair().

Here is the call graph for this function:
Here is the caller graph for this function: