ソースを参照

set2 t2 finished

api_change
コミット
f871bf7fff
5個のファイルの変更243行の追加211行の削除
  1. +3
    -0
      MatsanoCrypto
  2. +136
    -195
      MatsanoCrypto.sublime-workspace
  3. +101
    -15
      set2/runner.c
  4. +2
    -0
      set2/runner.h
  5. +1
    -1
      utils/common.c

+ 3
- 0
MatsanoCrypto ファイルの表示

@@ -6,6 +6,9 @@
},
{
"path": "/home/flowher/repos/notes"
},
{
"path": "/home/flowher/repos/OpenCrypto"
}
],
"settings":


+ 136
- 195
MatsanoCrypto.sublime-workspace ファイルの表示

@@ -3,6 +3,34 @@
{
"selected_items":
[
[
"EVP_En",
"EVP_EncryptFinal"
],
[
"size",
"size_t"
],
[
"un",
"uint8_t"
],
[
"ciph",
"ciphertext_len"
],
[
"con",
"concatenated_blocks"
],
[
"co",
"concatenated_blocks"
],
[
"uint",
"uint8_t"
],
[
"Resu",
"Result_Error"
@@ -486,108 +514,64 @@
[
"SEI_FAILE",
"SEI_FAILERROR_IF"
],
[
"Repositor",
"Repository::Instance"
],
[
"kInv",
"kSEIErr_InvalidPointer"
],
[
"PipeConnectorIn",
"PipeConnectorInterfacePtr"
],
[
"ConnectorI",
"ConnectorInterfacePtr"
],
[
"ConfigR",
"ConfigRowList_t"
],
[
"Reposi",
"Repository"
],
[
"ConfigDUSI",
"ConfigDUConState::processInsert"
]
]
},
"buffers":
[
{
"file": "utils/common.h",
"settings":
{
"buffer_size": 573,
"line_ending": "Unix"
}
},
{
"file": "set2/cbc.h",
"settings":
{
"buffer_size": 802,
"line_ending": "Unix"
}
},
{
"file": "set2/cbc.c",
"settings":
{
"buffer_size": 1425,
"buffer_size": 2409,
"line_ending": "Unix"
}
},
{
"file": "set1/ecb.h",
"file": "set2/runner.c",
"settings":
{
"buffer_size": 469,
"buffer_size": 4352,
"line_ending": "Unix"
}
},
{
"file": "set1/ecb.c",
"file": "/home/flowher/repos/OpenCrypto/crypto/evp/evp_enc.c",
"settings":
{
"buffer_size": 1842,
"buffer_size": 19470,
"line_ending": "Unix"
}
},
{
"file": "utils/xor.h",
"file": "/home/flowher/repos/OpenCrypto/include/openssl/evp.h",
"settings":
{
"buffer_size": 308,
"buffer_size": 71789,
"line_ending": "Unix"
}
},
{
"file": "set2/runner.c",
"file": "utils/common.c",
"settings":
{
"buffer_size": 1785,
"buffer_size": 1267,
"line_ending": "Unix"
}
},
{
"file": "set2/runner.h",
"file": "set1/ecb.c",
"settings":
{
"buffer_size": 222,
"buffer_size": 1843,
"line_ending": "Unix"
}
},
{
"file": "utils/common.c",
"file": "set2/runner.h",
"settings":
{
"buffer_size": 1273,
"buffer_size": 338,
"line_ending": "Unix"
}
}
@@ -607,6 +591,10 @@
"markdown",
"Markdown Preview: Preview in Browser"
],
[
"mard",
"Markdown Preview: Preview in Browser"
],
[
"markdow",
"Markdown Preview: Preview in Browser"
@@ -639,10 +627,6 @@
"git diff",
"Git: Diff All Files"
],
[
"mard",
"Markdown Preview: Preview in Browser"
],
[
"markdo",
"Markdown Preview: Preview in Browser"
@@ -992,31 +976,48 @@
"/home/flowher/repos/MatasanoCrypto/set2",
"/home/flowher/repos/MatasanoCrypto/utils",
"/home/flowher/repos/notes",
"/home/flowher/repos/notes/hacking"
"/home/flowher/repos/notes/hacking",
"/home/flowher/repos/OpenCrypto",
"/home/flowher/repos/OpenCrypto/crypto",
"/home/flowher/repos/OpenCrypto/crypto/aes",
"/home/flowher/repos/OpenCrypto/crypto/cmac",
"/home/flowher/repos/OpenCrypto/crypto/ec",
"/home/flowher/repos/OpenCrypto/crypto/ecdsa",
"/home/flowher/repos/OpenCrypto/crypto/evp"
],
"file_history":
[
"/home/flowher/repos/MatasanoCrypto/set1/runner.cpp",
"/home/flowher/repos/MatasanoCrypto/Makefile",
"/home/flowher/repos/OpenCrypto/engines/e_gmp.c",
"/home/flowher/repos/OpenCrypto/engines/ccgost/e_gost_err.c",
"/home/flowher/repos/OpenCrypto/engines/ccgost/gost89.c",
"/home/flowher/repos/OpenCrypto/engines/ccgost/gost_asn1.c",
"/home/flowher/repos/OpenCrypto/engines/ccgost/gostsum.c",
"/home/flowher/repos/OpenCrypto/engines/e_aep.c",
"/home/flowher/repos/notes/crypto/eliptic.md",
"/home/flowher/repos/notes/coding/SOLID.md",
"/home/flowher/repos/MatasanoCrypto/set2/cbc.h",
"/home/flowher/repos/MatasanoCrypto/set2/cbc.c",
"/home/flowher/repos/MatasanoCrypto/set1/ecb.c",
"/home/flowher/repos/MatasanoCrypto/utils/common.c",
"/home/flowher/repos/MatasanoCrypto/set2/runner.h",
"/home/flowher/repos/MatasanoCrypto/set2/runner.c",
"/home/flowher/repos/MatasanoCrypto/utils/xor.h",
"/home/flowher/repos/MatasanoCrypto/utils/common.h",
"/home/flowher/repos/MatasanoCrypto/Makefile",
"/home/flowher/repos/MatasanoCrypto/set1/runner.cpp",
"/home/flowher/repos/MatasanoCrypto/set1/runner.h",
"/home/flowher/repos/MatasanoCrypto/utils/runner.h",
"/home/flowher/repos/MatasanoCrypto/main.cpp",
"/home/flowher/repos/MatasanoCrypto/utils/runner.cpp",
"/home/flowher/repos/MatasanoCrypto/set1/xor_char_finder.cpp",
"/home/flowher/repos/MatasanoCrypto/set2/runner.c",
"/home/flowher/repos/MatasanoCrypto/set1/xor_char_finder.h",
"/home/flowher/repos/MatasanoCrypto/utils/pkcs7.h",
"/home/flowher/repos/MatasanoCrypto/set2/cbc.c",
"/home/flowher/repos/MatasanoCrypto/set1/ecb.c",
"/home/flowher/repos/MatasanoCrypto/utils/pkcs7.c",
"/home/flowher/repos/MatasanoCrypto/utils/common.c",
"/home/flowher/repos/MatasanoCrypto/utils/base64.cpp",
"/home/flowher/backup_server",
"/home/flowher/repos/notes/hacking/WPA.md",
"/home/flowher/repos/notes/hacking/WPA.mde",
"/home/flowher/server_snapshot.sh",
"/home/flowher/repos/MatasanoCrypto/utils/common.h",
"/home/flowher/test.c",
"/home/flowher/repos/MatasanoCrypto/utils/sets_runner.cpp",
"/home/flowher/repos/MatasanoCrypto/utils/utils_tester.cpp",
@@ -1030,7 +1031,6 @@
"/home/flowher/repos/MatasanoCrypto/utils/hamming.h",
"/home/flowher/repos/MatasanoCrypto/utils/hex_to_base64.cpp",
"/home/flowher/repos/MatasanoCrypto/utils/hex_to_base64.h",
"/home/flowher/repos/MatasanoCrypto/utils/xor.h",
"/home/flowher/repos/MatasanoCrypto/utils/xor.c",
"/home/kkwiatkowski/storage/91_Repositories/MatasanoCrypto/utils/xor.c",
"/home/kkwiatkowski/storage/91_Repositories/MatasanoCrypto/utils/hex_to_base64.cpp",
@@ -1114,16 +1114,7 @@
"/home/kkwiatkowski/test.cpp",
"/home/kkwiatkowski/amadeus_workdir/repos/Tracer_br_12-0-0/include/TRC_Exception.h",
"/home/kkwiatkowski/storage/91_Repositories/openssl101j/ssl/t1_clnt.c",
"/home/kkwiatkowski/storage/91_Repositories/openssl101j/crypto/seed/seed_ofb.c",
"/home/kkwiatkowski/amadeus_workdir/repos/01_OTF/br_12-0/include/otf/SignOutConfig.h",
"/home/kkwiatkowski/amadeus_workdir/repos/02_SI/br_5-1/test/regression/UTF/005_soapContentEncoding.play",
"/home/kkwiatkowski/amadeus_workdir/repos/02_SI/br_5-1/connector/src/AcceptorConnector.cpp",
"/home/kkwiatkowski/amadeus_workdir/repos/02_SI/br_5-1/process/src/async/AsyncCmdsCtx.cpp",
"/home/kkwiatkowski/amadeus_workdir/repos/03_Components/ACF/br_12-0-0/include/ACF_Connector.h",
"/home/kkwiatkowski/amadeus_workdir/repos/02_SI/br_5-1/agent/src/Agent.cpp",
"/home/kkwiatkowski/amadeus_workdir/repos/03_Components/ACF/br_12-0-0/src/network/TCPAcceptor.cpp",
"/home/kkwiatkowski/amadeus_workdir/repos/02_SI/br_5-1/config/include/si/model/TableClientProfile.h",
"/home/kkwiatkowski/storage/91_Repositories/openssl101j/crypto/srp/srp_lib.c"
"/home/kkwiatkowski/storage/91_Repositories/openssl101j/crypto/seed/seed_ofb.c"
],
"find":
{
@@ -1198,6 +1189,14 @@
"case_sensitive": false,
"find_history":
[
"EVP_aes_128_cbc",
"_op",
"EVP_CipherInit(",
"EVP_CipherInit",
"_init(",
"RSA_METHOD",
"ENGINE_CMD_DEFN",
"plaintext",
"xor_repeatedly",
" k",
" ",
@@ -1317,15 +1316,7 @@
"PWD_CB_ARGS",
"testClientServerSRPAuthCallbacks",
"SSL_CTX_set_srp_username",
"SSL_set_srp_server_param",
"set_srp_username",
"SSL_CTX_set_srp_username",
"4",
"setCommonOptions",
"Server",
"SocketAddress",
"Socket",
"56667"
"SSL_set_srp_server_param"
],
"highlight": true,
"in_selection": false,
@@ -1393,83 +1384,89 @@
[
{
"buffer": 0,
"file": "utils/common.h",
"file": "set2/cbc.c",
"semi_transient": false,
"settings":
{
"buffer_size": 573,
"buffer_size": 2409,
"regions":
{
},
"selection":
[
[
374,
374
132,
132
]
],
"settings":
{
"syntax": "Packages/C Improved/C Improved.tmLanguage"
"syntax": "Packages/C Improved/C Improved.tmLanguage",
"tab_size": 4,
"translate_tabs_to_spaces": true
},
"translation.x": 0.0,
"translation.y": 0.0,
"zoom_level": 1.0
},
"stack_index": 6,
"stack_index": 3,
"type": "text"
},
{
"buffer": 1,
"file": "set2/cbc.h",
"file": "set2/runner.c",
"semi_transient": false,
"settings":
{
"buffer_size": 802,
"buffer_size": 4352,
"regions":
{
},
"selection":
[
[
78,
78
3588,
3588
]
],
"settings":
{
"syntax": "Packages/C Improved/C Improved.tmLanguage"
"syntax": "Packages/C Improved/C Improved.tmLanguage",
"tab_size": 4,
"translate_tabs_to_spaces": true
},
"translation.x": 0.0,
"translation.y": 0.0,
"translation.y": 1746.0,
"zoom_level": 1.0
},
"stack_index": 1,
"stack_index": 2,
"type": "text"
},
{
"buffer": 2,
"file": "set2/cbc.c",
"file": "/home/flowher/repos/OpenCrypto/crypto/evp/evp_enc.c",
"semi_transient": false,
"settings":
{
"buffer_size": 1425,
"buffer_size": 19470,
"regions":
{
},
"selection":
[
[
476,
476
5507,
5507
]
],
"settings":
{
"syntax": "Packages/C Improved/C Improved.tmLanguage"
"syntax": "Packages/C Improved/C Improved.tmLanguage",
"tab_size": 4,
"translate_tabs_to_spaces": true
},
"translation.x": 0.0,
"translation.y": 0.0,
"translation.y": 2018.0,
"zoom_level": 1.0
},
"stack_index": 0,
@@ -1477,47 +1474,19 @@
},
{
"buffer": 3,
"file": "set1/ecb.h",
"semi_transient": true,
"settings":
{
"buffer_size": 469,
"regions":
{
},
"selection":
[
[
0,
0
]
],
"settings":
{
"syntax": "Packages/C Improved/C Improved.tmLanguage"
},
"translation.x": 0.0,
"translation.y": 0.0,
"zoom_level": 1.0
},
"stack_index": 5,
"type": "text"
},
{
"buffer": 4,
"file": "set1/ecb.c",
"file": "/home/flowher/repos/OpenCrypto/include/openssl/evp.h",
"semi_transient": false,
"settings":
{
"buffer_size": 1842,
"buffer_size": 71789,
"regions":
{
},
"selection":
[
[
65,
65
35951,
35951
]
],
"settings":
@@ -1527,55 +1496,56 @@
"translate_tabs_to_spaces": true
},
"translation.x": 0.0,
"translation.y": 0.0,
"translation.y": 14467.0,
"zoom_level": 1.0
},
"stack_index": 4,
"stack_index": 1,
"type": "text"
},
{
"buffer": 5,
"file": "utils/xor.h",
"buffer": 4,
"file": "utils/common.c",
"semi_transient": false,
"settings":
{
"buffer_size": 308,
"buffer_size": 1267,
"regions":
{
},
"selection":
[
[
37,
37
0,
0
]
],
"settings":
{
"syntax": "Packages/C Improved/C Improved.tmLanguage"
"syntax": "Packages/C Improved/C Improved.tmLanguage",
"translate_tabs_to_spaces": false
},
"translation.x": 0.0,
"translation.y": 0.0,
"zoom_level": 1.0
},
"stack_index": 3,
"stack_index": 4,
"type": "text"
},
{
"buffer": 6,
"file": "set2/runner.c",
"buffer": 5,
"file": "set1/ecb.c",
"semi_transient": false,
"settings":
{
"buffer_size": 1785,
"buffer_size": 1843,
"regions":
{
},
"selection":
[
[
1777,
1777
25,
25
]
],
"settings":
@@ -1585,27 +1555,27 @@
"translate_tabs_to_spaces": true
},
"translation.x": 0.0,
"translation.y": 199.0,
"translation.y": 0.0,
"zoom_level": 1.0
},
"stack_index": 2,
"stack_index": 5,
"type": "text"
},
{
"buffer": 7,
"buffer": 6,
"file": "set2/runner.h",
"semi_transient": false,
"settings":
{
"buffer_size": 222,
"buffer_size": 338,
"regions":
{
},
"selection":
[
[
182,
182
148,
148
]
],
"settings":
@@ -1616,36 +1586,7 @@
"translation.y": 0.0,
"zoom_level": 1.0
},
"stack_index": 7,
"type": "text"
},
{
"buffer": 8,
"file": "utils/common.c",
"semi_transient": false,
"settings":
{
"buffer_size": 1273,
"regions":
{
},
"selection":
[
[
1057,
1057
]
],
"settings":
{
"syntax": "Packages/C Improved/C Improved.tmLanguage",
"translate_tabs_to_spaces": false
},
"translation.x": 0.0,
"translation.y": 73.0,
"zoom_level": 1.0
},
"stack_index": 8,
"stack_index": 6,
"type": "text"
}
]
@@ -1653,7 +1594,7 @@
],
"incremental_find":
{
"height": 25.0
"height": 34.0
},
"input":
{
@@ -1723,6 +1664,10 @@
"last_filter": "",
"selected_items":
[
[
"evp.h",
"OpenCrypto/include/openssl/evp.h"
],
[
"xor.h",
"MatasanoCrypto/utils/xor.h"
@@ -2230,10 +2175,6 @@
[
"cmdnewsetdelbasepeakversiontest",
"SI/masteragent/test/src/CmdNewSetDelBasePeakVersionTest.cpp"
],
[
"sei_librarystaterepos",
"SI/masteragent/systemstate/src/SEI_LibraryStateRepository.cpp"
]
],
"width": 0.0


+ 101
- 15
set2/runner.c ファイルの表示

@@ -4,26 +4,66 @@
#include <stdio.h>
#include <string.h>
#include "cbc.h"
#include <openssl/evp.h>
#include <openssl/rand.h>

struct SyncOperations
{
int (*init)( EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
const unsigned char *key, const unsigned char *iv);
int (*update)(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
const unsigned char *in, int inl);
int (*final)(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl);
};

struct SyncOperations EncryptOps = {
.init = EVP_EncryptInit,
.update = EVP_EncryptUpdate,
.final = EVP_EncryptFinal
};

struct SyncOperations DecryptOps = {
.init = EVP_DecryptInit,
.update = EVP_DecryptUpdate,
.final = EVP_DecryptFinal
};

enum Op {
kEncrypt = 0,
kDecrypt
};

struct OpenSSL
{
static void EncryptCbc(const unsigned char* i_stream,
const uint32_t i_stream_size,
const unsigned char* i_pass,
const uint32_t i_pass_size,
unsigned char* o_buff)
static uint8_t Cbc( const uint8_t* i_stream, uint32_t i_stream_size,
const uint8_t* iv, uint32_t iv_len,
const unsigned char* i_pass, int32_t i_pass_size, uint8_t op,
uint8_t** o_buff, size_t* o_buff_len)
{
/* int ret, ret_fin;
struct SyncOperations sop = EncryptOps;
if(op == kDecrypt)
sop = DecryptOps;

if(NULL==*o_buff)
{
*o_buff = (uint8_t*) malloc(i_stream_size);
}

int ret, ret_fin;
ret=ret_fin=0;
EVP_CIPHER_CTX ctx;

EVP_DecryptInit(&ctx, EVP_aes_128_ecb(), NULL, NULL);
EVP_CIPHER_CTX_init(&ctx);
sop.init(&ctx, EVP_aes_128_cbc(), i_pass, iv);
EVP_CIPHER_CTX_set_padding(&ctx, 0);
EVP_CIPHER_CTX_set_key_length(&ctx, i_pass_size);
EVP_EncryptInit (&ctx, NULL, i_pass, NULL);
EVP_EncryptUpdate(&ctx, o_buff, &ret, i_stream, i_stream_size);
EVP_EncryptFinal (&ctx, o_buff+ret, &ret_fin);
return ret+ret_fin;
*/ }

// for...
sop.update(&ctx, *o_buff, &ret, i_stream, i_stream_size);
sop.final (&ctx, (*o_buff)+ret, &ret_fin);
*o_buff_len = ret+ret_fin;
return 1;
}

};

FUNC(pkcs7_test)
@@ -59,7 +99,7 @@ FUNC(cbc_decrypt_test)

uint8_t** p = &plaintext;
decrypt_cbc(iv, 16, buff, len, key, 16, p, &len);
printf("%s\n", plaintext);
//todo: printf("%s\n", plaintext);
}
FUNC_E

@@ -79,7 +119,53 @@ FUNC(cbc_enc_dec_test)
uint8_t** b = &b1;
encrypt_cbc(iv, 16, test_text, sizeof(test_text)-1, key, 16, p, &len);
decrypt_cbc(iv, 16, *p, len, key, 16, b, &len);
printf("%s\n", buff);
//todo: printf("%s\n", buff);
}
FUNC_E


FUNC(encode_decode_openssl)
{
uint8_t concatenated_blocks[16*3];
uint8_t iv1[16] = {0};
uint8_t key[17] = "YELLOW SUBMARINE"; // 16+'\0' = 17
uint8_t* ciphertext = NULL;
size_t ciphertext_len = 0;
uint8_t* out = NULL;
size_t out_len = 0;
Result_t res = Result_Error;
memset(concatenated_blocks, 2, 16);
memset(&concatenated_blocks[16], 5, 16);
memset(&concatenated_blocks[32], 9, 16);

RAND_bytes(iv1, 16);

check( 1 == OpenSSL::Cbc(concatenated_blocks, 48,
iv1, 16,
key, 16,
kEncrypt,
&ciphertext, &ciphertext_len),
(uint8_t*)"OpenSSL encryption failed");

// test decryption
check(ciphertext_len==48, (uint8_t*)"Ciphertext has wrong size");
res = decrypt_cbc(iv1, 16, ciphertext, ciphertext_len, key, 16, &out, &out_len );
check( Result_OK == res );
check( memcmp(concatenated_blocks, out, 48) == 0, (uint8_t*)"Input/Output differs");

// test encryption
ciphertext_len = 0;
out_len = 0;
res = encrypt_cbc(iv1, 16, concatenated_blocks, 48, key, 16, &ciphertext, &ciphertext_len );
check( Result_OK == res );
check(ciphertext_len==48, (uint8_t*)"Ciphertext has wrong size");
check( 1 == OpenSSL::Cbc(ciphertext, 48,
iv1, 16,
key, 16,
kDecrypt,
&out, &out_len),
(uint8_t*)"OpenSSL encryption failed");
check(ciphertext_len==48, (uint8_t*)"Ciphertext has wrong size");
check( memcmp(concatenated_blocks, out, 48) == 0, (uint8_t*)"Input/Output differs");
}
FUNC_E

+ 2
- 0
set2/runner.h ファイルの表示

@@ -4,6 +4,7 @@
void pkcs7_test();
void cbc_decrypt_test();
void cbc_enc_dec_test();
void encode_decode_openssl();

struct SET2
{
@@ -12,6 +13,7 @@ struct SET2
pkcs7_test();
cbc_decrypt_test();
cbc_enc_dec_test();
encode_decode_openssl();
}
};



+ 1
- 1
utils/common.c ファイルの表示

@@ -56,7 +56,7 @@ Result_t load_base64_to_hex(const char* const filepath, uint8_t* hex_buffer, siz
}

// this is needed for tests
void check(int iFlag, const unsigned char* const msg)
void check(int iFlag, const uint8_t* const msg)
{
if(!iFlag)
{


読み込み中…
キャンセル
保存