Selaa lähdekoodia

SET3.18

master
Krzysztof Kwiatkowski 8 vuotta sitten
vanhempi
commit
a3cf2fcfc3
4 muutettua tiedostoa jossa 32 lisäystä ja 16 poistoa
  1. +0
    -3
      sol/set2.c
  2. +27
    -11
      src/common.h
  3. +2
    -1
      src/enc_modes.h
  4. +3
    -1
      src/main.cpp

+ 0
- 3
sol/set2.c Näytä tiedosto

@@ -75,9 +75,6 @@ TCASE(ecb_encrypt_decrypt_single_block)
CHECK(memcmp(decode.output, expected_result, 16) == 0);
free(encode.output);
free(decode.output);
//CryptoAttribs_t::Free(&encode);
//CryptoAttribs_t::Free(&decode);
//Key_t::Free(&key1);
}
TCASE_E



+ 27
- 11
src/common.h Näytä tiedosto

@@ -21,6 +21,7 @@ void __CheckFunc__(bool iFlag, const char* const file, int line, const uint8_t*
// Some useful defines
#define MIN(a,b) a<b ? a : b
#define ROUNDUP_16_BYTES(X) (((X+15)/16) * 16)
#define AES_BLOCK_SIZE 16

#define OP_CHECK(exp) \
do { \
@@ -47,6 +48,28 @@ typedef enum {
kPadding_PKCS7
} PaddingType;

typedef struct CtrCtx_t {
uint8_t nonce[8];
uint8_t counter[8];
uint8_t encrypted_counter[AES_BLOCK_SIZE];
} CtrCtx_t;

typedef struct ModeCtx_t {
uint8_t iv[AES_BLOCK_SIZE];
CtrCtx_t ctr;
} ModeCtx_t;

/* -------------------------------------------------------------------------
Structure for key passing
-------------------------------------------------------------------------*/
typedef struct Key_t {
uint8_t* key;
size_t len;

static void Init(Key_t* ctx);
static void Free(Key_t* ctx);
} Key_t;

/* -------------------------------------------------------------------------
Struct used for symmetric encryption
-------------------------------------------------------------------------*/
@@ -57,25 +80,18 @@ struct CryptoAttribs_t {
size_t output_len;
uint8_t* iv;
size_t iv_len;
uint64_t output_cursor;

CryptoOperation operation;
ModeCtx_t mode;
// If requested, padding will align produced block size with key size
PaddingType padding;
Key_t key;

static void Init(CryptoAttribs_t* ctx);
static void Free(CryptoAttribs_t* ctx);
};

/* -------------------------------------------------------------------------
Structure for key passing
-------------------------------------------------------------------------*/
struct Key_t {
uint8_t* key;
size_t len;

static void Init(Key_t* ctx);
static void Free(Key_t* ctx);
};

struct int24 {
unsigned int data:24;
};


+ 2
- 1
src/enc_modes.h Näytä tiedosto

@@ -3,7 +3,8 @@

#include "common.h"

Result_t crypt( CryptoAttribs_t* attribs, const Key_t* const key );
void process_block(uint8_t in[16], uint8_t out[16], const Key_t* const key, bool encrypt);
Result_t aes_whole_blocks( CryptoAttribs_t* attribs, const Key_t* const key );

Result_t cbc_encrypt( CryptoAttribs_t* attribs, const Key_t* const key );
Result_t cbc_decrypt( CryptoAttribs_t* attribs, const Key_t* const key );


+ 3
- 1
src/main.cpp Näytä tiedosto

@@ -1,5 +1,6 @@
#include "sol/set1.h"
#include "sol/set2.h"
#include "sol/set3.h"
#include "tst/utils.h"

#include <openssl/conf.h>
@@ -13,9 +14,10 @@ int main()
ERR_load_crypto_strings();
OpenSSL_add_all_algorithms();

SET3::run();

SET2::run();
SET1::run();
SET2::run();
UTILS::run();

/* Clean up */


Ladataan…
Peruuta
Tallenna