gwenhywfar 5.10.1
Macros | Functions | Variables
padd.c File Reference
#include "padd_p.h"
#include <gwenhywfar/misc.h>
#include <gwenhywfar/debug.h>
#include <gwenhywfar/error.h>
#include <gwenhywfar/cryptdefs.h>
#include <gwenhywfar/text.h>
#include <string.h>
#include <stdlib.h>
Include dependency graph for padd.c:

Go to the source code of this file.

Macros

#define DISABLE_DEBUGLOG
 

Functions

int GWEN_Padd__UnpaddWithPkcs1Bt1Or2 (GWEN_BUFFER *buf)
 
int GWEN_Padd_AddPkcs1Pss (uint8_t *pDestBuffer, GWEN_UNUSED uint32_t lDestBuffer, uint32_t nbits, const uint8_t *pHash, uint32_t lHash, uint32_t lSalt, GWEN_MDIGEST *md)
 
int GWEN_Padd_ApplyPaddAlgo (const GWEN_CRYPT_PADDALGO *a, GWEN_BUFFER *buf)
 
int GWEN_Padd_MGF1 (uint8_t *pDestBuffer, uint32_t lDestBuffer, const uint8_t *pSeed, uint32_t lSeed, GWEN_MDIGEST *md)
 
int GWEN_Padd_PaddWithAnsiX9_23 (GWEN_BUFFER *src)
 
int GWEN_Padd_PaddWithAnsiX9_23ToMultipleOf (GWEN_BUFFER *src, int y)
 
int GWEN_Padd_PaddWithISO9796 (GWEN_BUFFER *src)
 
int GWEN_Padd_PaddWithIso9796_2 (GWEN_BUFFER *buf, int dstSize)
 
int GWEN_Padd_PaddWithPkcs1Bt1 (GWEN_BUFFER *buf, int dstSize)
 
int GWEN_Padd_PaddWithPkcs1Bt2 (GWEN_BUFFER *buf, int dstSize)
 
int GWEN_Padd_PaddWithZka (GWEN_BUFFER *src)
 
int GWEN_Padd_PaddWithZkaToMultipleOf (GWEN_BUFFER *src, int y)
 
unsigned char GWEN_Padd_permutate (unsigned char input)
 
int GWEN_Padd_UnapplyPaddAlgo (const GWEN_CRYPT_PADDALGO *a, GWEN_BUFFER *buf)
 
int GWEN_Padd_UnpaddWithAnsiX9_23 (GWEN_BUFFER *src)
 
int GWEN_Padd_UnpaddWithAnsiX9_23FromMultipleOf (GWEN_BUFFER *src, int y)
 
int GWEN_Padd_UnpaddWithIso9796_2 (GWEN_BUFFER *buf)
 
int GWEN_Padd_UnpaddWithPkcs1Bt1 (GWEN_BUFFER *src)
 
int GWEN_Padd_UnpaddWithPkcs1Bt2 (GWEN_BUFFER *src)
 
int GWEN_Padd_UnpaddWithZka (GWEN_BUFFER *buf)
 
int GWEN_Padd_UnpaddWithZkaFromMultipleOf (GWEN_BUFFER *buf, int y)
 
int GWEN_Padd_VerifyPkcs1Pss (const uint8_t *pSrcBuffer, uint32_t lSrcBuffer, uint32_t nbits, const uint8_t *pHash, uint32_t lHash, uint32_t lSalt, GWEN_MDIGEST *md)
 

Variables

static uint8_t nullarray [] = {0, 0, 0, 0, 0, 0, 0, 0}
 

Macro Definition Documentation

◆ DISABLE_DEBUGLOG

#define DISABLE_DEBUGLOG

Definition at line 30 of file padd.c.

Function Documentation

◆ GWEN_Padd__UnpaddWithPkcs1Bt1Or2()

int GWEN_Padd__UnpaddWithPkcs1Bt1Or2 ( GWEN_BUFFER buf)

Definition at line 367 of file padd.c.

References DBG_ERROR, GWEN_Buffer_Crop(), GWEN_Buffer_GetStart(), GWEN_Buffer_GetUsedBytes(), GWEN_ERROR_INVALID, and GWEN_LOGDOMAIN.

Referenced by GWEN_Padd_UnpaddWithPkcs1Bt1(), and GWEN_Padd_UnpaddWithPkcs1Bt2().

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

◆ GWEN_Padd_AddPkcs1Pss()

int GWEN_Padd_AddPkcs1Pss ( uint8_t *  pDestBuffer,
GWEN_UNUSED uint32_t  lDestBuffer,
uint32_t  nbits,
const uint8_t *  pHash,
uint32_t  lHash,
uint32_t  lSalt,
GWEN_MDIGEST md 
)

Definition at line 495 of file padd.c.

References DBG_INFO, GWEN_Crypt_Random(), GWEN_LOGDOMAIN, GWEN_MDigest_Begin(), GWEN_MDigest_End(), GWEN_MDigest_GetDigestPtr(), GWEN_MDigest_GetDigestSize(), GWEN_MDigest_Update(), GWEN_Padd_MGF1(), NULL, and nullarray.

Referenced by GWEN_Crypt_TokenFile__Sign().

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

◆ GWEN_Padd_ApplyPaddAlgo()

int GWEN_Padd_ApplyPaddAlgo ( const GWEN_CRYPT_PADDALGO a,
GWEN_BUFFER buf 
)

◆ GWEN_Padd_MGF1()

int GWEN_Padd_MGF1 ( uint8_t *  pDestBuffer,
uint32_t  lDestBuffer,
const uint8_t *  pSeed,
uint32_t  lSeed,
GWEN_MDIGEST md 
)

Definition at line 436 of file padd.c.

References DBG_INFO, GWEN_LOGDOMAIN, GWEN_MDigest_Begin(), GWEN_MDigest_End(), GWEN_MDigest_GetDigestPtr(), GWEN_MDigest_GetDigestSize(), and GWEN_MDigest_Update().

Referenced by GWEN_Padd_AddPkcs1Pss(), and GWEN_Padd_VerifyPkcs1Pss().

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

◆ GWEN_Padd_PaddWithAnsiX9_23()

int GWEN_Padd_PaddWithAnsiX9_23 ( GWEN_BUFFER src)

This is a compatibility function (calls GWEN_Padd_PaddWithAnsiX9_23ToMultipleOf with param y=8).

Definition at line 271 of file padd.c.

References GWEN_Padd_PaddWithAnsiX9_23ToMultipleOf().

Referenced by GWEN_Crypt_TokenOHBCI_Write(), GWEN_CryptMgr_Encrypt(), and GWEN_Padd_ApplyPaddAlgo().

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

◆ GWEN_Padd_PaddWithAnsiX9_23ToMultipleOf()

int GWEN_Padd_PaddWithAnsiX9_23ToMultipleOf ( GWEN_BUFFER src,
int  y 
)

This function is used to pad the plain text data to a multiple of 8 bytes size before encrypting it. This is done by adding bytes to the buffer until its length is multiple of Y bytes. The byte added is the number of padding bytes appended. Example: Y is 8, buffer initially contains 5 bytes, so 3 bytes are needed to make the buffer length a multiple of 8. So the number "3" is added three times. Please note that if the buffer initially has a multiple of Y bytes then Y bytes are added (this is needed to make sure the unpadd function can always recover data padded in this manner).

Definition at line 232 of file padd.c.

References GWEN_Buffer_AppendByte(), and GWEN_Buffer_GetUsedBytes().

Referenced by GWEN_Padd_PaddWithAnsiX9_23().

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

◆ GWEN_Padd_PaddWithISO9796()

int GWEN_Padd_PaddWithISO9796 ( GWEN_BUFFER src)

This function padds the given buffer according to ISO9796. The given buffer is expected to contain a 20 byte hash created using RIPEMD 160. This is padded to 96 bytes according to ISO 9796 (including appendix A4).

Definition at line 76 of file padd.c.

References DBG_INFO, GWEN_Buffer_AppendBytes(), GWEN_Buffer_Crop(), GWEN_Buffer_GetStart(), GWEN_Buffer_GetUsedBytes(), GWEN_Buffer_Reset(), GWEN_LOGDOMAIN, and GWEN_Padd_permutate().

Referenced by GWEN_Padd_ApplyPaddAlgo().

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

◆ GWEN_Padd_PaddWithIso9796_2()

int GWEN_Padd_PaddWithIso9796_2 ( GWEN_BUFFER buf,
int  dstSize 
)

This function padds according to ISO 8786-2.

Definition at line 148 of file padd.c.

References DBG_ERROR, GWEN_Buffer_AppendByte(), GWEN_Buffer_GetStart(), GWEN_Buffer_GetUsedBytes(), GWEN_Buffer_InsertRoom(), GWEN_Buffer_Rewind(), GWEN_Crypt_Random(), GWEN_ERROR_GENERIC, GWEN_ERROR_INVALID, and GWEN_LOGDOMAIN.

Referenced by check2(), GWEN_CryptMgrKeys_EncryptKey(), GWEN_CryptMgrKeys_SignData(), GWEN_Padd_ApplyPaddAlgo(), and GWEN_SmallTresor_Encrypt().

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

◆ GWEN_Padd_PaddWithPkcs1Bt1()

int GWEN_Padd_PaddWithPkcs1Bt1 ( GWEN_BUFFER buf,
int  dstSize 
)

Definition at line 285 of file padd.c.

References DBG_ERROR, GWEN_Buffer_GetStart(), GWEN_Buffer_GetUsedBytes(), GWEN_Buffer_InsertRoom(), GWEN_Buffer_Rewind(), GWEN_ERROR_GENERIC, GWEN_ERROR_INVALID, and GWEN_LOGDOMAIN.

Referenced by GWEN_Padd_ApplyPaddAlgo().

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

◆ GWEN_Padd_PaddWithPkcs1Bt2()

int GWEN_Padd_PaddWithPkcs1Bt2 ( GWEN_BUFFER buf,
int  dstSize 
)

Definition at line 324 of file padd.c.

References DBG_ERROR, GWEN_Buffer_GetStart(), GWEN_Buffer_GetUsedBytes(), GWEN_Buffer_InsertRoom(), GWEN_Buffer_Rewind(), GWEN_Crypt_Random(), GWEN_ERROR_GENERIC, GWEN_ERROR_INVALID, and GWEN_LOGDOMAIN.

Referenced by GWEN_Padd_ApplyPaddAlgo().

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

◆ GWEN_Padd_PaddWithZka()

int GWEN_Padd_PaddWithZka ( GWEN_BUFFER src)

Definition at line 904 of file padd.c.

References GWEN_Padd_PaddWithZkaToMultipleOf().

Here is the call graph for this function:

◆ GWEN_Padd_PaddWithZkaToMultipleOf()

int GWEN_Padd_PaddWithZkaToMultipleOf ( GWEN_BUFFER src,
int  y 
)

Definition at line 911 of file padd.c.

References GWEN_Buffer_AppendByte(), and GWEN_Buffer_GetUsedBytes().

Referenced by GWEN_Padd_PaddWithZka().

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

◆ GWEN_Padd_permutate()

unsigned char GWEN_Padd_permutate ( unsigned char  input)

Definition at line 51 of file padd.c.

Referenced by GWEN_Padd_PaddWithISO9796().

Here is the caller graph for this function:

◆ GWEN_Padd_UnapplyPaddAlgo()

int GWEN_Padd_UnapplyPaddAlgo ( const GWEN_CRYPT_PADDALGO a,
GWEN_BUFFER buf 
)

◆ GWEN_Padd_UnpaddWithAnsiX9_23()

int GWEN_Padd_UnpaddWithAnsiX9_23 ( GWEN_BUFFER src)

This is a compatibility function (calls GWEN_Padd_UnpaddWithAnsiX9_23FromMultipleOf with param y=8).

Definition at line 278 of file padd.c.

References GWEN_Padd_UnpaddWithAnsiX9_23FromMultipleOf().

Referenced by GWEN_Crypt_TokenOHBCI__DecryptFile(), GWEN_CryptMgr_Decrypt(), and GWEN_Padd_UnapplyPaddAlgo().

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

◆ GWEN_Padd_UnpaddWithAnsiX9_23FromMultipleOf()

int GWEN_Padd_UnpaddWithAnsiX9_23FromMultipleOf ( GWEN_BUFFER src,
int  y 
)

This function is used to remove padding from plain text data after decrypting it.

Definition at line 245 of file padd.c.

References DBG_ERROR, GWEN_Buffer_Crop(), GWEN_Buffer_GetStart(), GWEN_Buffer_GetUsedBytes(), GWEN_Buffer_SetPos(), and GWEN_LOGDOMAIN.

Referenced by GWEN_Padd_UnpaddWithAnsiX9_23().

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

◆ GWEN_Padd_UnpaddWithIso9796_2()

int GWEN_Padd_UnpaddWithIso9796_2 ( GWEN_BUFFER buf)

Definition at line 196 of file padd.c.

References DBG_ERROR, GWEN_Buffer_Crop(), GWEN_Buffer_GetStart(), GWEN_Buffer_GetUsedBytes(), GWEN_ERROR_BAD_DATA, GWEN_ERROR_INVALID, and GWEN_LOGDOMAIN.

Referenced by check2(), GWEN_CryptMgrKeys_DecryptKey(), GWEN_CryptMgrKeys_VerifyData(), GWEN_Padd_UnapplyPaddAlgo(), and GWEN_SmallTresor_Decrypt().

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

◆ GWEN_Padd_UnpaddWithPkcs1Bt1()

int GWEN_Padd_UnpaddWithPkcs1Bt1 ( GWEN_BUFFER src)

Definition at line 422 of file padd.c.

References GWEN_Padd__UnpaddWithPkcs1Bt1Or2().

Referenced by GWEN_Padd_UnapplyPaddAlgo().

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

◆ GWEN_Padd_UnpaddWithPkcs1Bt2()

int GWEN_Padd_UnpaddWithPkcs1Bt2 ( GWEN_BUFFER src)

Definition at line 429 of file padd.c.

References GWEN_Padd__UnpaddWithPkcs1Bt1Or2().

Referenced by GWEN_Padd_UnapplyPaddAlgo().

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

◆ GWEN_Padd_UnpaddWithZka()

int GWEN_Padd_UnpaddWithZka ( GWEN_BUFFER buf)

Definition at line 968 of file padd.c.

References GWEN_Padd_UnpaddWithZkaFromMultipleOf().

Here is the call graph for this function:

◆ GWEN_Padd_UnpaddWithZkaFromMultipleOf()

int GWEN_Padd_UnpaddWithZkaFromMultipleOf ( GWEN_BUFFER buf,
int  y 
)

Definition at line 927 of file padd.c.

References DBG_ERROR, GWEN_Buffer_Crop(), GWEN_Buffer_GetStart(), GWEN_Buffer_GetUsedBytes(), GWEN_Buffer_SetPos(), and GWEN_LOGDOMAIN.

Referenced by GWEN_Padd_UnpaddWithZka().

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

◆ GWEN_Padd_VerifyPkcs1Pss()

int GWEN_Padd_VerifyPkcs1Pss ( const uint8_t *  pSrcBuffer,
uint32_t  lSrcBuffer,
uint32_t  nbits,
const uint8_t *  pHash,
uint32_t  lHash,
uint32_t  lSalt,
GWEN_MDIGEST md 
)

Definition at line 619 of file padd.c.

References DBG_ERROR, DBG_INFO, GWEN_ERROR_BAD_DATA, GWEN_ERROR_VERIFY, GWEN_LOGDOMAIN, GWEN_MDigest_Begin(), GWEN_MDigest_End(), GWEN_MDigest_GetDigestPtr(), GWEN_MDigest_GetDigestSize(), GWEN_MDigest_Update(), GWEN_Padd_MGF1(), and nullarray.

Referenced by GWEN_Crypt_TokenFile__Verify().

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

Variable Documentation

◆ nullarray

uint8_t nullarray[] = {0, 0, 0, 0, 0, 0, 0, 0}
static

Definition at line 44 of file padd.c.

Referenced by GWEN_Padd_AddPkcs1Pss(), and GWEN_Padd_VerifyPkcs1Pss().