Przeglądaj źródła

Coring

api_change
rodzic
commit
94f680e030
20 zmienionych plików z 2070 dodań i 565 usunięć
  1. +28
    -23
      Makefile
  2. +4
    -1
      prj/Matasano.sublime-project
  3. +535
    -185
      prj/Matasano.sublime-workspace
  4. +65
    -50
      sol/set1.cpp
  5. +93
    -63
      sol/set2.c
  6. +3
    -3
      sol/set2.h
  7. +0
    -2
      src/base64.cpp
  8. +6
    -1
      src/base64.h
  9. +0
    -93
      src/cbc.c
  10. +0
    -23
      src/cbc.h
  11. +100
    -15
      src/common.c
  12. +65
    -7
      src/common.h
  13. +0
    -61
      src/ecb.c
  14. +0
    -6
      src/ecb.h
  15. +157
    -0
      src/enc_modes.c
  16. +12
    -0
      src/enc_modes.h
  17. +4
    -1
      src/xor.c
  18. +6
    -1
      src/xor_char_finder.h
  19. +962
    -0
      suppressions.valgrind
  20. +30
    -30
      tst/utils.cpp

+ 28
- 23
Makefile Wyświetl plik

@@ -1,5 +1,6 @@
INC=.
LIBS=-lcrypto -lssl
CFLAGS=-g

SRC_C_FILES := $(wildcard src/*.c)
SRC_CPP_FILES := $(wildcard src/*.cpp)
@@ -16,30 +17,32 @@ TST_CPP_FILES := $(wildcard tst/*.cpp)
OBJ_TST_C_FILES := $(addprefix obj/,$(notdir $(TST_C_FILES:.c=.o)))
OBJ_TST_CPP_FILES := $(addprefix obj/,$(notdir $(TST_CPP_FILES:.cpp=.o)))

obj/%.o: src/%.cpp
g++ -I${INC} -o $@ -c $^
obj/%.o: src/%.cpp
g++ ${CFLAGS} -I${INC} -o $@ -c $^

obj/%.o: src/%.c
g++ -I${INC} -o $@ -c $^
g++ ${CFLAGS} -I${INC} -o $@ -c $^

obj/%.o: sol/%.cpp
g++ -I${INC} -o $@ -c $^
obj/%.o: sol/%.cpp
g++ ${CFLAGS} -I${INC} -o $@ -c $^

obj/%.o: sol/%.c
g++ -I${INC} -o $@ -c $^
g++ ${CFLAGS} -I${INC} -o $@ -c $^

obj/%.o: tst/%.cpp
g++ -I${INC} -o $@ -c $^
obj/%.o: tst/%.cpp
g++ ${CFLAGS} -I${INC} -o $@ -c $^

obj/%.o: tst/%.c
g++ -I${INC} -o $@ -c $^
g++ ${CFLAGS} -I${INC} -o $@ -c $^

obj-c: ${OBJ_SRC_C_FILES}
obj-cpp: ${OBJ_SRC_CPP_FILES}
sol-c: ${OBJ_SOL_C_FILES}
sol-cpp: ${OBJ_SOL_CPP_FILES}
tst-c: ${OBJ_TST_C_FILES}
tst-cpp: ${OBJ_TST_CPP_FILES}
all: create_directories obj-c obj-cpp sol-c sol-cpp tst-c tst-cpp
g++ ${CFLAGS} -I${INC} -o main ${OBJ_SRC_C_FILES} \
${OBJ_SRC_CPP_FILES} \
${OBJ_SOL_C_FILES} \
${OBJ_SOL_CPP_FILES} \
${OBJ_TST_C_FILES} \
${OBJ_TST_CPP_FILES} \
${LIBS}

create_directories:
mkdir -p obj
@@ -49,11 +52,13 @@ clean:
rm -rf main
rm -rf core*

all: create_directories obj-c obj-cpp sol-c sol-cpp tst-c tst-cpp
g++ -I${INC} -o main ${OBJ_SRC_C_FILES} \
${OBJ_SRC_CPP_FILES} \
${OBJ_SOL_C_FILES} \
${OBJ_SOL_CPP_FILES} \
${OBJ_TST_C_FILES} \
${OBJ_TST_CPP_FILES} \
${LIBS}
obj-c: ${OBJ_SRC_C_FILES}
obj-cpp: ${OBJ_SRC_CPP_FILES}
sol-c: ${OBJ_SOL_C_FILES}
sol-cpp: ${OBJ_SOL_CPP_FILES}
tst-c: ${OBJ_TST_C_FILES}
tst-cpp: ${OBJ_TST_CPP_FILES}

.PHONY: valgrind
valgrind:
valgrind --suppressions=suppressions.valgrind --leak-check=full ./main

+ 4
- 1
prj/Matasano.sublime-project Wyświetl plik

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

+ 535
- 185
prj/Matasano.sublime-workspace Wyświetl plik

@@ -3,6 +3,62 @@
{
"selected_items":
[
[
"Resu",
"Result_Error"
],
[
"output",
"output_len"
],
[
"inpu",
"input"
],
[
"input",
"input_len"
],
[
"Cry",
"CryptoAttribs_t"
],
[
"base",
"base64_buf"
],
[
"outp",
"output_len"
],
[
"in",
"input"
],
[
"i_",
"i_content"
],
[
"ci",
"Ciphertext"
],
[
"plain",
"plaintext"
],
[
"cip",
"ciphertext_len"
],
[
"Encryptio",
"EncryptionContent_t"
],
[
"out",
"output"
],
[
"EVP_En",
"EVP_EncryptFinal"
@@ -31,10 +87,6 @@
"uint",
"uint8_t"
],
[
"Resu",
"Result_Error"
],
[
"o_",
"o_buff_ptr"
@@ -43,14 +95,6 @@
"key",
"key_len"
],
[
"in",
"input_buff"
],
[
"base",
"base64_to_hex"
],
[
"count",
"count_array_size"
@@ -107,10 +151,6 @@
"frequency",
"frequency_t"
],
[
"cip",
"ciphertext_len"
],
[
"let",
"letter"
@@ -474,51 +514,83 @@
[
"getBac",
"getBackRoutingKey"
],
[
"test",
"unit_test"
],
[
"boost",
"boosttestcase boosttestcase"
],
[
"kSEIEr",
"kSEIErr_InvalidPointer"
],
[
"aBuff",
"aBufferPos"
],
[
"get",
"getSITK"
],
[
"_get",
"_getCxnDetails"
],
[
"_ccn",
"_ccnConnectionStatus"
],
[
"Remote",
"RemoteConnectorVisitor"
],
[
"SEI_Command",
"SEI_CommandGroupDef"
],
[
"SEI_FAILE",
"SEI_FAILERROR_IF"
]
]
},
"buffers":
[
{
"file": "/home/flowher/repos/MatasanoCrypto/sol/set1.cpp",
"settings":
{
"buffer_size": 12489,
"line_ending": "Unix"
}
},
{
"file": "/home/flowher/repos/MatasanoCrypto/sol/set2.h",
"settings":
{
"buffer_size": 342,
"line_ending": "Unix"
}
},
{
"file": "/home/flowher/test.cpp",
"settings":
{
"buffer_size": 282,
"line_ending": "Unix"
}
},
{
"file": "/home/flowher/repos/MatasanoCrypto/src/hamming.c",
"settings":
{
"buffer_size": 1690,
"line_ending": "Unix"
}
},
{
"file": "/home/flowher/repos/MatasanoCrypto/src/base64.cpp",
"settings":
{
"buffer_size": 8033,
"line_ending": "Unix"
}
},
{
"file": "/home/flowher/repos/MatasanoCrypto/src/xor_char_finder.cpp",
"settings":
{
"buffer_size": 6026,
"line_ending": "Unix"
}
},
{
"file": "/home/flowher/repos/MatasanoCrypto/sol/set2.c",
"settings":
{
"buffer_size": 5962,
"line_ending": "Unix"
}
},
{
"file": "/home/flowher/repos/MatasanoCrypto/src/enc_modes.c",
"settings":
{
"buffer_size": 4546,
"line_ending": "Unix"
}
},
{
"file": "/home/flowher/repos/notes/french/words/words.md",
"settings":
{
"buffer_size": 757,
"line_ending": "Unix"
}
}
],
"build_system": "",
"build_system_choices":
@@ -527,14 +599,38 @@
"build_varint": "",
"command_palette":
{
"height": 392.0,
"last_filter": "markdown",
"height": 201.0,
"last_filter": "",
"selected_items":
[
[
"install",
"Package Control: Install Package"
],
[
"check",
"Google Spell Check"
],
[
"comme",
"Snippet: comment-simple"
],
[
"newhfi",
"Snippet: newhfile"
],
[
"newh",
"Snippet: newhfile"
],
[
"markdown",
"Markdown Preview: Preview in Browser"
],
[
"git add",
"Git: Add Current File"
],
[
"mard",
"Markdown Preview: Preview in Browser"
@@ -551,14 +647,6 @@
"comment",
"Toggle Comment"
],
[
"comme",
"Snippet: comment-method"
],
[
"install",
"Package Control: Install Package"
],
[
"snippet",
"Snippet: comment"
@@ -743,10 +831,6 @@
"newclas",
"Snippet: newclass"
],
[
"newhfi",
"Snippet: newhfile"
],
[
"fixture",
"Snippet: new_boost_fixture_test_suite"
@@ -892,7 +976,7 @@
"Package Control: Install Package"
]
],
"width": 575.0
"width": 467.0
},
"console":
{
@@ -915,10 +999,39 @@
},
"expanded_folders":
[
"/home/flowher/repos/MatasanoCrypto"
"/home/flowher/repos/MatasanoCrypto",
"/home/flowher/repos/MatasanoCrypto/sol",
"/home/flowher/repos/MatasanoCrypto/src"
],
"file_history":
[
"/home/flowher/repos/notes/french/words/words.md",
"/home/flowher/repos/MatasanoCrypto/Makefile",
"/home/flowher/repos/MatasanoCrypto/src/enc_modes.c",
"/home/flowher/repos/MatasanoCrypto/src/xor.c",
"/home/flowher/Work/zshrc",
"/home/flowher/repos/MatasanoCrypto/src/common.h",
"/home/flowher/repos/MatasanoCrypto/src/common.c",
"/home/flowher/repos/MatasanoCrypto/tst/utils.cpp",
"/home/flowher/Work/.source",
"/home/flowher/repos/MatasanoCrypto/src/enc_modes.h",
"/home/flowher/repos/MatasanoCrypto/src/cbc.c",
"/home/flowher/repos/MatasanoCrypto/src/cbc.h",
"/home/flowher/repos/MatasanoCrypto/src/xor_char_finder.h",
"/home/flowher/repos/MatasanoCrypto/src/base64.h",
"/home/flowher/repos/MatasanoCrypto/suppressions.valgrind",
"/home/flowher/repos/MatasanoCrypto/src/base64.cpp",
"/home/flowher/repos/MatasanoCrypto/tst/utils.h",
"/home/flowher/repos/MatasanoCrypto/src/ecb.c",
"/home/flowher/test.cpp",
"/home/flowher/test.c",
"/home/flowher/.config/sublime-text-3/Packages/User/Preferences.sublime-settings",
"/home/flowher/repos/MatasanoCrypto/prj/Matasano.sublime-project",
"/home/flowher/repos/MatasanoCrypto/sol/set2.h",
"/home/flowher/repos/MatasanoCrypto/sol/set1.cpp",
"/home/flowher/repos/MatasanoCrypto/src/main.cpp",
"/home/flowher/repos/notes/french/words/words",
"/home/flowher/repos/MatasanoCrypto/sol/main.cpp",
"/home/flowher/repos/notes/crypto/eliptic.md",
"/home/flowher/repos/notes/coding/SOLID.md",
"/home/flowher/repos/MatasanoCrypto/set2/cbc.h",
@@ -929,7 +1042,6 @@
"/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",
@@ -944,7 +1056,6 @@
"/home/flowher/repos/notes/hacking/WPA.md",
"/home/flowher/repos/notes/hacking/WPA.mde",
"/home/flowher/server_snapshot.sh",
"/home/flowher/test.c",
"/home/flowher/repos/MatasanoCrypto/utils/sets_runner.cpp",
"/home/flowher/repos/MatasanoCrypto/utils/utils_tester.cpp",
"/home/flowher/repos/MatasanoCrypto/utils/hamming.c",
@@ -1021,36 +1132,11 @@
"/home/kkwiatkowski/amadeus_workdir/repos/03_Components/acf_ssl/br_12-0-1/src/SSLEngineInit.cpp",
"/home/kkwiatkowski/storage/91_Repositories/openssl101j/ssl/ssltest.c",
"/home/kkwiatkowski/storage/91_Repositories/openssl101j/test/ssltest",
"/home/kkwiatkowski/storage/91_Repositories/openssl101j/apps/s_client.c",
"/home/kkwiatkowski/amadeus_workdir/project_files/si_head.sublime-project",
"/home/kkwiatkowski/storage/91_Repositories/openssl101j/crypto/srp/srp_vfy.c",
"/home/kkwiatkowski/storage/91_Repositories/openssl101j/crypto/srp/srp.h",
"/home/kkwiatkowski/amadeus_workdir/repos/03_Components/acf_ssl/br_12-0-1/test/src/KeyTest.cpp",
"/home/kkwiatkowski/amadeus_workdir/repos/03_Components/ACF/br_12-0-0/src/network/TCPSocket.cpp",
"/home/kkwiatkowski/amadeus_workdir/repos/03_Components/ACF/br_12-0-0/src/network/Socket.cpp",
"/home/kkwiatkowski/amadeus_workdir/repos/03_Components/ACF/br_12-0-0/include/acf/network/Socket.h",
"/home/kkwiatkowski/amadeus_workdir/repos/03_Components/ACF/br_12-0-0/include/acf/network/Acceptor.h",
"/home/kkwiatkowski/amadeus_workdir/repos/03_Components/ACF/br_12-0-0/include/acf/network/TCPAcceptor.h",
"/home/kkwiatkowski/diff_after_review_1.diff",
"/home/kkwiatkowski/amadeus_workdir/repos/03_Components/acf_ssl/br_12-0-1/include/acf/ssl/CertificateStore.h",
"/home/kkwiatkowski/amadeus_workdir/repos/03_Components/acf_ssl/br_12-0-1/include/acf/ssl/Key.h",
"/home/kkwiatkowski/amadeus_workdir/repos/01_OTF/br_12-0/include/otf/Export.h",
"/home/kkwiatkowski/storage/91_Repositories/openssl101j/crypto/crypto.h",
"/home/kkwiatkowski/storage/91_Repositories/openssl101j/crypto/mem.c",
"/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/storage/91_Repositories/openssl101j/apps/s_client.c"
],
"find":
{
"height": 25.0
"height": 35.0
},
"find_in_files":
{
@@ -1121,6 +1207,80 @@
"case_sensitive": false,
"find_history":
[
"cbc_enc_dec_test",
"g++ ",
"memcpy",
"ecb_attribs->",
"Init",
"cbc_decrypt_test",
"load_base64_to_hex",
"cbc_decrypt_test",
"SET1_T7",
"SET1_T7_INPUT_FILE",
"attribs->",
"key->",
"kris",
"ecb_attribs->",
"tmpbuff",
"Cbc(",
"readr",
"uint8_t",
"free",
"FUNC_E",
"FUNC(",
"t4_input",
"ecb_decrypt",
"strlen",
"uint32_t",
"same_blocks",
"key",
"Key_t&",
"key",
"iv",
"attribs",
"16",
"iv",
"valgrind",
"ain)\n",
"==2596==",
"check(",
"__CHECK__",
"check3",
"GET_4TH_ARG",
"PRINT_STRING_MACRO_CHOOSER",
"check",
"base64_buff",
"read_file_to_buffer",
"load_base64_to_hex",
"content",
"i_content",
"EncryptionContent_t",
"ciphertext",
"i_content.",
"ctx.",
"Init(",
"Cbc",
"o_buff",
"utils",
"sol/",
"SOL_",
"etc/",
"etc",
"utils",
"src/",
"set",
"set-",
"SRC",
"SRC_",
"src/",
"set1",
"utils",
"set1",
"utils",
"set2/",
"set1/",
"utils/",
"utils",
"RSA_METHOD",
"ENGINE_CMD_DEFN",
"plaintext",
@@ -1174,81 +1334,7 @@
"gcc",
"fill_frequency",
"#define FREQUENT_LETTERS_AMOUNT 5\n",
"size_t",
"xorable_chars",
"p_ciphertext_xor",
"printf",
"char_in_array",
"printf",
"letters_number",
"xor",
"printf",
"xor_strings",
"z",
"read_by",
"char_to_hex",
"hex_buff",
"Asynchat",
"__handler",
"input_handler_class",
"ProtocolHandler",
"decode(",
"segment",
"Reconnect",
"Reactor",
"Dispatcher",
"Reactor",
"GenericClient",
"Generic",
"TcilClientConnection",
"ClientConnection",
"Connection",
"process_iedi_message",
"ProtocolHandler",
"ProtocolHandl",
"TransportProtocolHandlerBase",
"reinterpret_cast",
"EDH",
"ECDH",
"EDH",
"\"EDH\"",
"\"STRONG\"",
"STRONG",
"EDHC",
"DEBUG",
"TRC1ASIEDI",
"IN{cfg.srv[0].name}-TCIL",
"socket",
"ssl",
"SSLTrafficEventHandler",
"setHandshakeTimer",
"Leak",
"Memcheck:Leak",
"setSrpUsernameCallback",
"SRP_server_callback",
"PWD_CB_ARGS",
"USER_NAME",
"SSL_CTX_set_srp_password",
"srpCliPwdCb",
"USER_PASS",
"PWD_CB_ARGS",
"srpCliPwdCb",
"SRP_server_callback",
"setVerifyPeer",
"PWD_CB_ARGS",
"SRP_server_callback",
"SSL_CTX_set_srp_client_pwd_callback",
"setSrpPwdCallback",
"USER_NAME",
"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"
"size_t"
],
"highlight": true,
"in_selection": false,
@@ -1256,6 +1342,9 @@
"regex": false,
"replace_history":
[
"TCASE_E",
"TCASE(",
"CHECK(",
"RandomSleep",
"BOOST_CHECK",
"BOOST_CHECK_EQUAL",
@@ -1311,8 +1400,269 @@
"groups":
[
{
"selected": 8,
"sheets":
[
{
"buffer": 0,
"file": "/home/flowher/repos/MatasanoCrypto/sol/set1.cpp",
"semi_transient": false,
"settings":
{
"buffer_size": 12489,
"regions":
{
},
"selection":
[
[
11546,
11546
]
],
"settings":
{
"syntax": "Packages/C++/C++.tmLanguage",
"translate_tabs_to_spaces": false
},
"translation.x": 0.0,
"translation.y": 3788.0,
"zoom_level": 1.0
},
"stack_index": 4,
"type": "text"
},
{
"buffer": 1,
"file": "/home/flowher/repos/MatasanoCrypto/sol/set2.h",
"semi_transient": false,
"settings":
{
"buffer_size": 342,
"regions":
{
},
"selection":
[
[
231,
231
]
],
"settings":
{
"syntax": "Packages/C Improved/C Improved.tmLanguage"
},
"translation.x": 0.0,
"translation.y": 0.0,
"zoom_level": 1.0
},
"stack_index": 3,
"type": "text"
},
{
"buffer": 2,
"file": "/home/flowher/test.cpp",
"semi_transient": false,
"settings":
{
"buffer_size": 282,
"regions":
{
},
"selection":
[
[
133,
133
]
],
"settings":
{
"syntax": "Packages/C++/C++.tmLanguage"
},
"translation.x": 0.0,
"translation.y": 0.0,
"zoom_level": 1.0
},
"stack_index": 5,
"type": "text"
},
{
"buffer": 3,
"file": "/home/flowher/repos/MatasanoCrypto/src/hamming.c",
"semi_transient": false,
"settings":
{
"buffer_size": 1690,
"regions":
{
},
"selection":
[
[
69,
69
]
],
"settings":
{
"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": 7,
"type": "text"
},
{
"buffer": 4,
"file": "/home/flowher/repos/MatasanoCrypto/src/base64.cpp",
"semi_transient": false,
"settings":
{
"buffer_size": 8033,
"regions":
{
},
"selection":
[
[
100,
100
]
],
"settings":
{
"syntax": "Packages/C++/C++.tmLanguage",
"translate_tabs_to_spaces": false
},
"translation.x": 0.0,
"translation.y": 0.0,
"zoom_level": 1.0
},
"stack_index": 6,
"type": "text"
},
{
"buffer": 5,
"file": "/home/flowher/repos/MatasanoCrypto/src/xor_char_finder.cpp",
"semi_transient": false,
"settings":
{
"buffer_size": 6026,
"regions":
{
},
"selection":
[
[
4445,
4445
]
],
"settings":
{
"syntax": "Packages/C++/C++.tmLanguage",
"translate_tabs_to_spaces": false
},
"translation.x": 0.0,
"translation.y": 1014.0,
"zoom_level": 1.0
},
"stack_index": 8,
"type": "text"
},
{
"buffer": 6,
"file": "/home/flowher/repos/MatasanoCrypto/sol/set2.c",
"semi_transient": false,
"settings":
{
"buffer_size": 5962,
"regions":
{
},
"selection":
[
[
2918,
2918
]
],
"settings":
{
"syntax": "Packages/C Improved/C Improved.tmLanguage",
"tab_size": 4,
"translate_tabs_to_spaces": true
},
"translation.x": 0.0,
"translation.y": 1264.0,
"zoom_level": 1.0
},
"stack_index": 2,
"type": "text"
},
{
"buffer": 7,
"file": "/home/flowher/repos/MatasanoCrypto/src/enc_modes.c",
"semi_transient": false,
"settings":
{
"buffer_size": 4546,
"regions":
{
},
"selection":
[
[
4483,
4483
]
],
"settings":
{
"syntax": "Packages/C Improved/C Improved.tmLanguage",
"tab_size": 4,
"translate_tabs_to_spaces": true
},
"translation.x": 0.0,
"translation.y": 1893.0,
"zoom_level": 1.0
},
"stack_index": 1,
"type": "text"
},
{
"buffer": 8,
"file": "/home/flowher/repos/notes/french/words/words.md",
"semi_transient": false,
"settings":
{
"buffer_size": 757,
"regions":
{
},
"selection":
[
[
245,
245
]
],
"settings":
{
"syntax": "Packages/MarkdownEditing/Markdown.tmLanguage"
},
"translation.x": 0.0,
"translation.y": 0.0,
"zoom_level": 1.0
},
"stack_index": 0,
"type": "text"
}
]
}
],
@@ -1389,12 +1739,16 @@
"selected_items":
[
[
"xor.h",
"MatasanoCrypto/utils/xor.h"
"common.c",
"MatasanoCrypto/src/common.c"
],
[
"common.c",
"MatasanoCrypto/utils/common.c"
"common.h",
"MatasanoCrypto/src/common.h"
],
[
"xor.h",
"MatasanoCrypto/utils/xor.h"
],
[
"iedi.py",
@@ -1895,10 +2249,6 @@
[
"cmdnewsetdelbasepeakversiontest",
"SI/masteragent/test/src/CmdNewSetDelBasePeakVersionTest.cpp"
],
[
"sei_librarystaterepos",
"SI/masteragent/systemstate/src/SEI_LibraryStateRepository.cpp"
]
],
"width": 0.0
@@ -2205,7 +2555,7 @@
"show_open_files": true,
"show_tabs": false,
"side_bar_visible": true,
"side_bar_width": 212.0,
"side_bar_width": 207.0,
"status_bar_visible": true,
"template_settings":
{


+ 65
- 50
sol/set1.cpp Wyświetl plik

@@ -3,13 +3,14 @@
#include "src/base64.h"
#include "src/xor.h"
#include "src/hamming.h"
#include "src/ecb.h"
#include "src/enc_modes.h"

#include <stdlib.h>
#include <stdio.h>
#include <string.h>


#define SET1_T4_INPUT_FILE "sol/etc/set1_t4_input.txt"
#define SET1_T7_INPUT_FILE "sol/etc/set1_t7.txt"
#define SET1_T8_INPUT_FILE "sol/etc/set1_t8.txt"

char guess_encryption_key_letter(const char ciphertext_hex[])
@@ -25,7 +26,7 @@ char guess_encryption_key_letter(const char ciphertext_hex[])
return max_score.letter;
}

FUNC(set1_challenge3_test)
TCASE(set1_challenge3_test)
{
static const char ciphertext[] = "1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736";
unsigned char buf[2];
@@ -34,12 +35,12 @@ FUNC(set1_challenge3_test)
ret = guess_encryption_key_letter(ciphertext);

sprintf((char*)buf, "%c", ret);
check(ret == 'X', buf);
CHECK(ret == 'X', buf);
}
FUNC_E
TCASE_E


FUNC(xor_char_finder_test)
TCASE(xor_char_finder_test)
{
// "This is my simple text."
unsigned char buf[256];
@@ -52,23 +53,23 @@ FUNC(xor_char_finder_test)

got = guess_encryption_key_letter(ciphertext_A);
sprintf((char*)buf, "Returned: [%c]", got);
check(got == 'A', buf);
CHECK(got == 'A', buf);

got = guess_encryption_key_letter(ciphertext_5);
sprintf((char*)buf, "Returned: [%c]", got);
check(got == '5', buf);
CHECK(got == '5', buf);

got = guess_encryption_key_letter(ciphertext_h);
sprintf((char*)buf, "Returned: [%c]", got);
check(got == 'h', buf);
CHECK(got == 'h', buf);

got = guess_encryption_key_letter(ciphertext_long);
sprintf((char*)buf, "Returned: [%c]", got);
check(got == 'M', buf);
CHECK(got == 'M', buf);
}
FUNC_E
TCASE_E

FUNC(set1_challange4_test)
TCASE(set1_challange4_test)
{
FILE* fp;
char* line=NULL;
@@ -77,10 +78,10 @@ FUNC(set1_challange4_test)
unsigned char hexdump[30];
unsigned char* p_hexdump = hexdump;

fp=fopen("sol/etc/set1_t4_input.txt", "r");
fp=fopen(SET1_T4_INPUT_FILE, "r");
if(fp==NULL)
{
fprintf(stderr, "sol/etc/set1_t4_input.txt not found");
fprintf(stderr, SET1_T4_INPUT_FILE " not found");
return;
}

@@ -120,9 +121,9 @@ FUNC(set1_challange4_test)
}
free(line);
}
FUNC_E
TCASE_E

FUNC(set1_challenge_5_test)
TCASE(set1_challenge_5_test)
{
const unsigned char ch1[] = "Burning 'em, if you ain't quick and nimble\nI go crazy when I hear a cymbal";
const unsigned char xor_val[] = "ICE";
@@ -140,19 +141,21 @@ FUNC(set1_challenge_5_test)
xor_repeatedly(xor_val, 3, ch1, sizeof(ch1), po_ch1);

for(unsigned i=0; i<sizeof(expected)/sizeof(unsigned char); ++i)
check( expected[i] == po_ch1[i] );
CHECK( expected[i] == po_ch1[i] );
}
FUNC_E
TCASE_E

FUNC(set1_challenge_6_test)
TCASE(set1_challenge_6_test)
{
const unsigned max_block_size=200;

char base64_buf[1024*1024]; // 1 MB
uint8_t* pbuff = (uint8_t*) &base64_buf[0];

char error_buf[256];
unsigned char out_buf[1024*1024];
unsigned char hex_buf[1024*1024];
unsigned long len=read_file_to_buffer("sol/etc/set1_t6.txt", base64_buf);
unsigned long len=read_file_to_buffer("sol/etc/set1_t6.txt", &pbuff, &len);
base64_buf[len]='\0';
len=base64_to_hex((unsigned char*)base64_buf, len, hex_buf);

@@ -162,17 +165,17 @@ FUNC(set1_challenge_6_test)

memset(out_buf,0,sizeof(out_buf));
int best_key_size = find_best_keysize(base64_buf, strlen(base64_buf));
check(best_key_size==29);
CHECK(best_key_size==29);
best_key_size=crack_repeted_xor(base64_buf, out_buf, best_key_size);
// check(memcmp(expected_plaintext1, out_buf, sizeof(expected_plaintext1))==0, out_buf);
// CHECK(memcmp(expected_plaintext1, out_buf, sizeof(expected_plaintext1))==0, out_buf);

// OZAPTF: to do, it works just need correct check
// check(memcmp(expected_plaintext3, buf, sizeof(expected_plaintext3))==0, buf);
// CHECK(memcmp(expected_plaintext3, buf, sizeof(expected_plaintext3))==0, buf);

}
FUNC_E
TCASE_E

FUNC(crack_repeted_xor_test)
TCASE(crack_repeted_xor_test)
{

unsigned char error_buf[256];
@@ -199,45 +202,57 @@ FUNC(crack_repeted_xor_test)
int best_key_size = find_best_keysize(hex_str1, strlen(hex_str1));
crack_repeted_xor(hex_str1, buf, best_key_size);
sprintf((char*)error_buf, "Wrong keysize. Expected 5 got %d\n", best_key_size);
check(best_key_size==5, error_buf);
check(memcmp(expected_plaintext1, buf, sizeof(expected_plaintext1))==0, buf);
CHECK(best_key_size==5, error_buf);
CHECK(memcmp(expected_plaintext1, buf, sizeof(expected_plaintext1))==0, buf);

// here I have to reduce key size otherwise with keylength 39 there is better score
memset(buf,0,sizeof(buf));
best_key_size = find_best_keysize(hex_str2, strlen(hex_str2),2,38);
crack_repeted_xor(hex_str2, buf, best_key_size);
sprintf((char*)error_buf, "Wrong keysize. Expected 13 got %d\n", best_key_size);
check(best_key_size==13, error_buf);
check(memcmp(expected_plaintext2, buf, sizeof(expected_plaintext2))==0, buf);
CHECK(best_key_size==13, error_buf);
CHECK(memcmp(expected_plaintext2, buf, sizeof(expected_plaintext2))==0, buf);

// here I have to reduce key size otherwise with keylength 39 there is better score
memset(buf,0,sizeof(buf));
best_key_size = find_best_keysize(hex_str3, strlen(hex_str3));
crack_repeted_xor(hex_str3, buf, best_key_size);
sprintf((char*)error_buf, "Wrong keysize. Expected 20 got %d\n", best_key_size);
check(best_key_size==20, error_buf);
check(memcmp(expected_plaintext3, buf, sizeof(expected_plaintext3))==0, buf);
CHECK(best_key_size==20, error_buf);
CHECK(memcmp(expected_plaintext3, buf, sizeof(expected_plaintext3))==0, buf);
}
FUNC_E
TCASE_E

FUNC(set1_challenge_7_test)
TCASE(set1_challenge_7_test)
{
const unsigned char pass[]="YELLOW SUBMARINE";
const char expected_first_line[] = "I'm back and I'm ringin' the bell";
unsigned char ciphertext[1024*1024]; // 1 MB
unsigned long len=read_file_to_buffer("sol/etc/set1_t7.txt", (char*)ciphertext);

unsigned char buff[1024*1024];
unsigned char hex[1024*1024];

int ret;
ret = base64_to_hex(ciphertext, len, &hex[0]);
ret = ecb_decrypt(hex, ret, pass, sizeof(pass), &buff[0]);
check(memcmp(buff, expected_first_line, strlen(expected_first_line))==0);
Result_t res = Result_Error;

CryptoAttribs_t attribs;
Key_t key;

CryptoAttribs_t::Init(&attribs);
Key_t::Init(&key);
key.len = 16;
key.key = (uint8_t*) malloc(key.len * sizeof(uint8_t));
memcpy(key.key, "YELLOW SUBMARINE", key.len);
res = load_base64_to_hex(
SET1_T7_INPUT_FILE,
&attribs.input,
&(attribs.input_len));
CHECK(res == Result_OK, (uint8_t*) "Error while loading ciphertext");
ecb_decrypt(&attribs, &key);
CHECK(
memcmp( attribs.output,
expected_first_line,
strlen(expected_first_line))==0, attribs.output);

Key_t::Free(&key);
CryptoAttribs_t::Free(&attribs);
}
FUNC_E
TCASE_E

FUNC(set1_challenge_8_test)
TCASE(set1_challenge_8_test)
{
FILE* fh=NULL;

@@ -266,8 +281,8 @@ FUNC(set1_challenge_8_test)
free(line);
fclose(fh);

check(current_line==133);
check(first==2);
check(second==4);
CHECK(current_line==133);
CHECK(first==2);
CHECK(second==4);
}
FUNC_E
TCASE_E

+ 93
- 63
sol/set2.c Wyświetl plik

@@ -1,6 +1,6 @@
#include "src/common.h"
#include "src/pkcs7.h"
#include "src/cbc.h"
#include "src/enc_modes.h"
#include <assert.h>
#include <stdio.h>
#include <string.h>
@@ -28,45 +28,39 @@ struct SyncOperations DecryptOps = {
.final = EVP_DecryptFinal
};

enum Op {
kEncrypt = 0,
kDecrypt
};

struct OpenSSL
{
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)
static uint8_t Cbc(CryptoAttribs_t* i_attribs,
const Key_t* i_key)
{
struct SyncOperations sop = EncryptOps;
if(op == kDecrypt)
if(i_attribs->operation == kDecrypt)
sop = DecryptOps;

if(NULL==*o_buff)
if(NULL==i_attribs->output)
{
*o_buff = (uint8_t*) malloc(i_stream_size);
i_attribs->output = (uint8_t*) malloc(i_attribs->input_len);
}

int ret, ret_fin;
ret=ret_fin=0;
EVP_CIPHER_CTX ctx;
EVP_CIPHER_CTX_init(&ctx);
sop.init(&ctx, EVP_aes_128_cbc(), i_pass, iv);
sop.init(&ctx, EVP_aes_128_cbc(), i_key->key, i_attribs->iv);
EVP_CIPHER_CTX_set_padding(&ctx, 0);
EVP_CIPHER_CTX_set_key_length(&ctx, i_pass_size);
EVP_CIPHER_CTX_set_key_length(&ctx, i_key->len);

// 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;
sop.update(&ctx, i_attribs->output, &ret, i_attribs->input,
i_attribs->input_len);
sop.final (&ctx, (i_attribs->output)+ret, &ret_fin);
i_attribs->output_len = ret+ret_fin;
return 1;
}

};

FUNC(pkcs7_test)
TCASE(pkcs7_test)
{
// int pkcs7_pad(const char* i_buff, const size_t i_len, char* o_buff );
const char text1[] = "Text1";
@@ -76,55 +70,90 @@ FUNC(pkcs7_test)
char buff2[10];

ret = pkcs7_pad(text1, 5, buff1, 32);
check(ret==0, (const unsigned char* const) "Padding operation failed");
CHECK(ret==0, (const unsigned char* const) "Padding operation failed");
ret = memcmp(text1, buff1, 5);
check(ret==0, (const unsigned char* const) "Content differs");
CHECK(ret==0, (const unsigned char* const) "Content differs");
for(int i=5; i<32; i++)
{
check(buff1[i] == 27, (const unsigned char* const) "Wrong padding");
CHECK(buff1[i] == 27, (const unsigned char* const) "Wrong padding");
}
}
FUNC_E
TCASE_E


FUNC(cbc_decrypt_test)
TCASE(cbc_enc_dec_test)
{
uint8_t iv[16] = {0};
uint8_t* plaintext = NULL;
uint8_t key[17] = "YELLOW SUBMARINE"; // 16+'\0' = 17
size_t len = 0;
uint8_t buff[4096] = {0};
Result_t res = Result_Error;
static const uint8_t test_text[49] = "The quick brown fox jumps over the lazy mad dog.";

res = load_base64_to_hex("sol/etc/set2_t2.txt", buff, &len);
CryptoAttribs_t attribs;
Key_t key;

uint8_t** p = &plaintext;
decrypt_cbc(iv, 16, buff, len, key, 16, p, &len);
//todo: printf("%s\n", plaintext);
}
FUNC_E
Key_t::Init(&key);
key.len = 16;
key.key = (uint8_t*) malloc(key.len);
memcpy(key.key, "YELLOW SUBMARINE", key.len);

FUNC(cbc_enc_dec_test)
{
uint8_t iv[16] = {0};
uint8_t* ciphertext = NULL;
uint8_t key[17] = "YELLOW SUBMARINE"; // 16+'\0' = 17
size_t len = 0;
uint8_t buff[4096] = {0};
Result_t res = Result_Error;
CryptoAttribs_t::Init(&attribs);
attribs.input_len = 48;
attribs.input = (uint8_t*) malloc(attribs.input_len);
memcpy( attribs.input, test_text, attribs.input_len);

attribs.iv_len = key.len;
attribs.iv = (uint8_t*) malloc(attribs.iv_len);
memset(attribs.iv, '0', attribs.iv_len);

cbc_encrypt(&attribs, &key);

free(attribs.input);
attribs.input = (uint8_t*) malloc(attribs.output_len);
attribs.input_len = attribs.output_len;
memcpy(attribs.input, attribs.output, attribs.output_len);

uint8_t test_text[49] = "The quick brown fox jumps over the lazy mad dog.";
free(attribs.output);
attribs.output = NULL;
attribs.output_len = 0;

uint8_t** p = &ciphertext;
uint8_t* b1 = &buff[0];
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);
//todo: printf("%s\n", buff);
cbc_decrypt(&attribs, &key);
CHECK(memcmp(attribs.output, test_text, attribs.output_len) == 0, attribs.output);
Key_t::Free(&key);
CryptoAttribs_t::Init(&attribs);
}
FUNC_E
TCASE_E


FUNC(encode_decode_openssl)
TCASE(cbc_decrypt_test)
{
CryptoAttribs_t attribs;
Key_t key;
Result_t res = Result_Error;

Key_t::Init(&key);
key.len = 16;
key.key = (uint8_t*) malloc(key.len * sizeof(uint8_t));
memcpy(key.key,"YELLOW SUBMARINE",key.len);

CryptoAttribs_t::Init(&attribs);
attribs.iv = (uint8_t*) malloc(key.len * sizeof(uint8_t));
attribs.iv_len = key.len;
memset(attribs.iv, '0', attribs.iv_len);

res = load_base64_to_hex(
"sol/etc/set2_t2.txt",
&(attribs.input),
&(attribs.input_len));

CHECK(res == Result_OK, (const uint8_t*) "Problem when loading input file");
cbc_decrypt(&attribs, &key);
printf("%.20s\n", attribs.output);

CryptoAttribs_t::Free(&attribs);
Key_t::Free(&key);
}
TCASE_E
/*
TCASE(encode_decode_openssl)
{
uint8_t concatenated_blocks[16*3];
uint8_t iv1[16] = {0};
@@ -140,7 +169,7 @@ FUNC(encode_decode_openssl)

RAND_bytes(iv1, 16);

check( 1 == OpenSSL::Cbc(concatenated_blocks, 48,
CHECK( 1 == OpenSSL::Cbc(concatenated_blocks, 48,
iv1, 16,
key, 16,
kEncrypt,
@@ -148,24 +177,25 @@ FUNC(encode_decode_openssl)
(uint8_t*)"OpenSSL encryption failed");

// test decryption
check(ciphertext_len==48, (uint8_t*)"Ciphertext has wrong size");
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");
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,
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");
CHECK(ciphertext_len==48, (uint8_t*)"Ciphertext has wrong size");
CHECK( memcmp(concatenated_blocks, out, 48) == 0, (uint8_t*)"Input/Output differs");
}
FUNC_E
TCASE_E
*/

+ 3
- 3
sol/set2.h Wyświetl plik

@@ -4,16 +4,16 @@
void pkcs7_test();
void cbc_decrypt_test();
void cbc_enc_dec_test();
void encode_decode_openssl();
//void encode_decode_openssl();

struct SET2
{
static void run()
{
pkcs7_test();
cbc_decrypt_test();
cbc_enc_dec_test();
encode_decode_openssl();
cbc_decrypt_test();
//encode_decode_openssl();
}
};



+ 0
- 2
src/base64.cpp Wyświetl plik

@@ -4,8 +4,6 @@
#include "base64.h"
#include "common.h"

#define MIN(a,b) a<b ? a : b

static const unsigned short char_to_hex[256] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,


+ 6
- 1
src/base64.h Wyświetl plik

@@ -1,6 +1,11 @@
#ifndef _base64_H_
#define _base64_H_

unsigned hex_to_base64(const char* hex_buff, char* base64_buff, unsigned hex_buff_len );
int base64_to_hex(const unsigned char* const i_string, int i_string_len, unsigned char* o_hex_array );
void convert_string_to_hex(const char* const iArray, const unsigned iArrayLen, unsigned char* oHexArray);
void convert_hex_to_string(const unsigned char* const iHexArray, unsigned iHexArrayLen, char* oStringBuf );
void xor_strings(const char* const iLeftString, const char* const iRightString, unsigned char* oXorArray);
int c2b(char T);
int c2b(char T);

#endif /* _base64_ */

+ 0
- 93
src/cbc.c Wyświetl plik

@@ -1,93 +0,0 @@
#include "src/xor.h"
#include "src/common.h"
#include "src/ecb.h"
#include "src/ecb.h"
#include <stdio.h>
#include <stdlib.h>

Result_t decrypt_cbc( uint8_t* iv,
size_t iv_len,
uint8_t* input_buff,
size_t buff_len,
uint8_t* key,
size_t key_len,
uint8_t** output_buff,
size_t* result_len)
{
uint8_t tmpbuff[key_len];
*result_len=0;

if(buff_len % key_len != 0 )
return Result_Error;
const size_t bc = buff_len / key_len;

if(*output_buff == NULL)
{
// allocate size of ciphertext
*output_buff = (uint8_t*) malloc( (bc*key_len) +1);
}

for(int i=0; i<bc; ++i)
{
uint8_t* i_buff_ptr = input_buff+(key_len*i);
uint8_t* o_buff_ptr = (*output_buff)+(key_len*i);

// 1. Decrypt
ecb_decrypt(i_buff_ptr, key_len /*block size*/, key, key_len, tmpbuff);

// 2. Xor IV
xor_repeatedly(iv, iv_len, tmpbuff, key_len, (unsigned char*) o_buff_ptr);

// 3. Change iv with block
iv = i_buff_ptr;
*result_len += key_len;
}

return Result_OK;
}


Result_t encrypt_cbc( uint8_t* iv,
size_t iv_len,
uint8_t* input_buff,
size_t buff_len,
uint8_t* key,
size_t key_len,
uint8_t** output_buff,
size_t* result_len)
{
uint8_t tmpbuff[key_len];
*result_len=0;

if(buff_len % key_len != 0 )
return Result_Error;

if( iv_len != key_len )
return Result_Error;

const size_t bc = buff_len / key_len;

if(*output_buff == NULL)
{
*output_buff = (uint8_t*) malloc( bc*key_len );
}

for(int i=0; i<bc; ++i)
{
uint8_t* i_buff_ptr = input_buff+(key_len*i);
uint8_t* o_buff_ptr = (*output_buff)+(key_len*i);

// 2. Xor IV
xor_repeatedly(iv, key_len, i_buff_ptr, key_len, tmpbuff);

// 1. Decrypt
ecb_encrypt(tmpbuff, key_len /*block size*/, key, key_len, o_buff_ptr);

// 3. Change iv with block
iv = o_buff_ptr;

*result_len += key_len;
}

return Result_OK;
}

+ 0
- 23
src/cbc.h Wyświetl plik

@@ -1,23 +0,0 @@
#ifndef __cbc_h__
#define __cbc_h__

#include <stdint.h>

Result_t decrypt_cbc( uint8_t* iv,
size_t iv_len,
uint8_t* input_buff,
size_t buff_len,
uint8_t* key,
size_t key_len,
uint8_t** output_buff,
size_t* result_len);

Result_t encrypt_cbc( uint8_t* iv,
size_t iv_len,
uint8_t* input_buff,
size_t buff_len,
uint8_t* key,
size_t key_len,
uint8_t** output_buff,
size_t* result_len);
#endif // __cbc_h__

+ 100
- 15
src/common.c Wyświetl plik

@@ -5,10 +5,30 @@
#include "common.h"
#include "base64.h"

void __CheckFunc__(bool iFlag, const char* const file, int line, const uint8_t* const msg )
{
if(!iFlag)
{
if(msg)
{
fprintf(stderr, "ERROR[%s:%d]:%s\n", file, line, msg);
exit(1);
}
else
{
fprintf(stderr, "ERROR[%s:%d]\n", file, line);
exit(1);
}
}
}

unsigned long read_file_to_buffer( const char* const filepath,
char* obuff,
int remove_new_line_chr)
uint8_t** obuff,
bool remove_new_line_chr)
{
if(NULL==obuff || NULL==filepath)
return 0;

FILE* fh=0;
size_t len=0;
char* line=NULL;
@@ -20,22 +40,22 @@ unsigned long read_file_to_buffer( const char* const filepath,
exit(1);
}

if(NULL==obuff)
if(NULL==(*obuff))
{
//allocate
fseek(fh, 0, SEEK_END);
int pos = ftell(fh);
fseek(fh, 0, SEEK_SET);
obuff = (char*) malloc(pos);
*obuff = (uint8_t*) malloc(pos);
}

while( getline(&line, &len, fh) != -1 )
{
len = strlen(line);
len = strlen(line); // OZAPTF: needed? you have len above
if(remove_new_line_chr)
len--;

strncpy(obuff+total_len, line, len);
memcpy((*obuff)+total_len, line, len);
total_len+=len;
if(line!=NULL)
free(line);
@@ -45,22 +65,87 @@ unsigned long read_file_to_buffer( const char* const filepath,
return total_len;
}

Result_t load_base64_to_hex(const char* const filepath, uint8_t* hex_buffer, size_t* len)
Result_t load_base64_to_hex(const char* const filepath,
uint8_t** hex_buffer,
size_t* len)
{
char base64_buff[4000];
*len = read_file_to_buffer(filepath, base64_buff, 1);
if(hex_buffer == NULL)
return Result_Error;

uint8_t* tmpbuff = NULL;
*len = read_file_to_buffer(filepath, &tmpbuff, 1);
if(*len == 0)
return Result_Error;
base64_to_hex((unsigned char*) base64_buff, *len, hex_buffer);
*hex_buffer = (uint8_t*) malloc(*len);
base64_to_hex(tmpbuff, *len, *hex_buffer);
free(tmpbuff);

return Result_OK;
}

// this is needed for tests
void check(int iFlag, const uint8_t* const msg)

// checks if there are identical blocks in the i_textline
int same_blocks(const char* i_textline, const int i_bs, int* first_block, int* second_block)
{
int chunk_nb = strlen(i_textline)/i_bs;
for(int i=0; i<chunk_nb-1; i++)
{
for(int j=i+1; j<chunk_nb; j++)
{
if(memcmp(&i_textline[i*i_bs], &i_textline[j*i_bs],i_bs)==0)
{
*first_block = i+1;
*second_block = j+1;
return 1;
}
}
}
return 0;
}

void CryptoAttribs_t::Init(CryptoAttribs_t* ctx)
{
ctx->iv = NULL;
ctx->iv_len = 0;
ctx->output = NULL;
ctx->output_len = 0;
ctx->input = NULL;
ctx->input_len = 0;
ctx->operation = kEncrypt;
}

void CryptoAttribs_t::Free(CryptoAttribs_t* ctx)
{
if(!iFlag)
if(ctx->iv)
{
fprintf(stderr, "ERROR: %s\n", msg);
exit(1);
::free(ctx->iv);
ctx->iv=NULL;
}
if(ctx->output)
{
::free(ctx->output);
ctx->output=NULL;
}
if(ctx->input)
{
::free(ctx->input);
ctx->input=NULL;
}
ctx->iv_len = 0;
ctx->output_len = 0;
ctx->input_len = 0;
}

void Key_t::Init(Key_t* ctx)
{
ctx->key = NULL;
ctx->len = 0;
}


void Key_t::Free(Key_t* ctx)
{
if(ctx->key)
::free(ctx->key);
ctx->len = 0;
}

+ 65
- 7
src/common.h Wyświetl plik

@@ -3,9 +3,24 @@

#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>

#define FUNC(x) void x() { printf("Entering %s\n", __func__);
#define FUNC_E /*printf("Test done\n");*/ }
// Functions for logging start/stop of the test cases
#define TCASE(x) void x() { printf("Entering %s\n", __func__);
#define TCASE_E /*printf("Test done\n");*/ }

// When iFlag is false then function logs an error and halts program
void __CheckFunc__(bool iFlag, const char* const file, int line, const uint8_t* const msg = NULL );
#define __CHECK2__(Arg1,Msg) __CheckFunc__(Arg1,__FILE__,__LINE__, Msg)
#define __CHECK1__(Arg1) __CheckFunc__(Arg1,__FILE__,__LINE__)
#define __CHECK_MACRO_CHOOSER__(_1,_2, MACRO,...) MACRO
#define CHECK(...) __CHECK_MACRO_CHOOSER__(__VA_ARGS__, __CHECK2__, __CHECK1__)(__VA_ARGS__)

// Some useful defines
#define MIN(a,b) a<b ? a : b
#define ROUNDUP_16_BYTES(X) (((X+15)/16) * 16)

typedef enum
{
@@ -13,9 +28,52 @@ typedef enum
Result_Error
} Result_t;

void check(int iFlag, const unsigned char* const msg = 0);
struct int24 { unsigned int data:24; };
unsigned long read_file_to_buffer(const char* const filepath, char* obuff, int remove_new_line_chr = 1);
Result_t load_base64_to_hex(const char* const filepath, uint8_t* hex_buffer, size_t* len);
typedef enum {
kEncrypt = 0,
kDecrypt = 1
} CryptoOperation;

/* -------------------------------------------------------------------------
Struct used for symmetric encryption
-------------------------------------------------------------------------*/
struct CryptoAttribs_t {
uint8_t* input;
size_t input_len;
uint8_t* output;
size_t output_len;
uint8_t* iv;
size_t iv_len;
CryptoOperation operation;

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;
};


/* -------------------------------------------------------------------------
Misclleneus utilities
-------------------------------------------------------------------------*/
unsigned long read_file_to_buffer( const char* const filepath,
uint8_t** obuff,
bool remove_new_line_chr = false);

Result_t load_base64_to_hex(const char* const filepath, uint8_t** hex_buffer, size_t* len);

int same_blocks(const char* i_textline, const int i_bs, int* first_block, int* second_block);

#endif // __common_h__
#endif // __common_h__

+ 0
- 61
src/ecb.c Wyświetl plik

@@ -1,61 +0,0 @@
#include <openssl/evp.h>
#include <stdint.h>
#include <string.h>

uint32_t ecb_decrypt( 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)
{
int ret, ret_fin;
ret=ret_fin=0;
EVP_CIPHER_CTX ctx;
EVP_CIPHER_CTX_init(&ctx);

EVP_CipherInit_ex(&ctx, EVP_aes_128_ecb(), NULL, i_pass, NULL, 0);
EVP_CIPHER_CTX_set_key_length(&ctx, i_pass_size);

EVP_DecryptUpdate(&ctx, o_buff, &ret, i_stream, i_stream_size);
EVP_DecryptFinal (&ctx, o_buff+ret, &ret_fin);
return ret+ret_fin;
}


uint32_t ecb_encrypt( 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)
{
int ret, ret_fin;
ret=ret_fin=0;
EVP_CIPHER_CTX ctx;
EVP_CIPHER_CTX_init(&ctx);

EVP_EncryptInit (&ctx, EVP_aes_128_ecb(), i_pass, NULL);
EVP_CIPHER_CTX_set_key_length(&ctx, i_pass_size);

EVP_EncryptUpdate(&ctx, o_buff, &ret, i_stream, i_stream_size);
EVP_EncryptFinal (&ctx, o_buff+ret, &ret_fin);
return ret+ret_fin;
}

// checks if there are identical blocks in the i_textline
int same_blocks(const char* i_textline, const int i_bs, int* first_block, int* second_block)
{
int chunk_nb = strlen(i_textline)/i_bs;
for(int i=0; i<chunk_nb-1; i++)
{
for(int j=i+1; j<chunk_nb; j++)
{
if(memcmp(&i_textline[i*i_bs], &i_textline[j*i_bs],i_bs)==0)
{
*first_block = i+1;
*second_block = j+1;
return 1;
}
}
}
return 0;
}

+ 0
- 6
src/ecb.h Wyświetl plik

@@ -1,6 +0,0 @@
#include <stdint.h>

// return output buffer size
uint32_t ecb_decrypt(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);
uint32_t ecb_encrypt(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);
int same_blocks(const char* i_textline, const int i_bs, int* first_block, int* second_block);

+ 157
- 0
src/enc_modes.c Wyświetl plik

@@ -0,0 +1,157 @@
#include <stdint.h>
#include <string.h>
#include <inttypes.h>
#include <openssl/evp.h>
#include "common.h"
#include "xor.h"

Result_t ecb_decrypt(
CryptoAttribs_t* attribs,
const Key_t* const key)
{
// if output is NULL then allocate same size as input rounded to block size
if(attribs->output == NULL)
{
attribs->output = (uint8_t*) malloc(
ROUNDUP_16_BYTES(attribs->input_len) * sizeof(uint8_t));
}

int ret, ret_fin;
ret=ret_fin=0;
EVP_CIPHER_CTX ctx;
EVP_CIPHER_CTX_init(&ctx);

EVP_CipherInit_ex(&ctx, EVP_aes_128_ecb(), NULL, key->key, NULL, 0);
EVP_CIPHER_CTX_set_key_length(&ctx, key->len);

EVP_DecryptUpdate(&ctx, attribs->output, &ret, attribs->input, attribs->input_len);
EVP_DecryptFinal (&ctx, (attribs->output)+ret, (int*)&attribs->output_len);
return Result_OK;
}

Result_t ecb_encrypt(
CryptoAttribs_t* attribs,
const Key_t* const key)

{
// if output is NULL then allocate same size as input rounded to block size
if(attribs->output == NULL)
{
attribs->output = (uint8_t*) malloc(
ROUNDUP_16_BYTES(attribs->input_len) * sizeof(uint8_t));
}

int ret, ret_fin;
ret=ret_fin=0;
EVP_CIPHER_CTX ctx;
EVP_CIPHER_CTX_init(&ctx);

EVP_EncryptInit (&ctx, EVP_aes_128_ecb(), key->key, NULL);
EVP_CIPHER_CTX_set_key_length(&ctx, key->len);

EVP_EncryptUpdate(&ctx, attribs->output, &ret, attribs->input, attribs->input_len);
EVP_EncryptFinal (&ctx, (attribs->output)+ret, (int*)&attribs->output_len);
return Result_OK;
}


Result_t cbc_decrypt(
CryptoAttribs_t* attribs,
const Key_t* const key)
{
if((attribs->input_len % key->len) != 0 )
return Result_Error;
const size_t bc = attribs->input_len / key->len;
if( attribs->output == NULL)
{
// same as input + 16 bytes iv
const size_t len = (ROUNDUP_16_BYTES(attribs->input_len)+16);
attribs->output = (uint8_t*) malloc(len * sizeof(uint8_t));
attribs->output_len = len;
}

uint8_t* iv = attribs->iv;
CryptoAttribs_t ecb_attribs;
CryptoAttribs_t::Init(&ecb_attribs);
ecb_attribs.output = (uint8_t*) malloc(key->len);
ecb_attribs.output_len = key->len;

for(int i=0; i<bc; ++i)
{
ecb_attribs.input = (attribs->input)+(key->len*i);
ecb_attribs.input_len = key->len;

// 1. Decrypt
if( ecb_decrypt(&ecb_attribs, key) != Result_OK )
return Result_Error;

// 2. Xor IV
xor_repeatedly(
iv, attribs->iv_len,
ecb_attribs.output, ecb_attribs.output_len,
(attribs->output)+(key->len*i));

printf("%.16s\n", attribs->output);
// 3. Change iv with block
iv = ecb_attribs.input;
attribs->output_len += key->len;
}
free(ecb_attribs.output);

return Result_OK;
}

Result_t cbc_encrypt(
CryptoAttribs_t* attribs,
const Key_t* const key)
{
if((attribs->input_len % key->len) != 0 )
return Result_Error;

if( attribs->iv_len != key->len )
return Result_Error;

const size_t bc = attribs->input_len / key->len;

if( attribs->output == NULL)
{
// same as input + 16 bytes iv
attribs->output = (uint8_t*) malloc(
(ROUNDUP_16_BYTES(attribs->input_len)+16) * sizeof(uint8_t));
}

uint8_t* iv = attribs->iv;

CryptoAttribs_t ecb_attribs;
CryptoAttribs_t::Init(&ecb_attribs);
ecb_attribs.input = (uint8_t*) malloc(key->len);
ecb_attribs.input_len = key->len;
ecb_attribs.output = (uint8_t*) malloc(key->len);
ecb_attribs.output_len = key->len;
for(int i=0; i<bc; ++i)
{
uint8_t* i_buff_ptr = (attribs->input)+(key->len*i);

// 1. Xor IV
xor_repeatedly(
iv, attribs->iv_len,
i_buff_ptr, attribs->iv_len,
ecb_attribs.input);
ecb_attribs.input_len = key->len;

// 2. Encrypt
if( ecb_encrypt(&ecb_attribs, key) != Result_OK )
return Result_Error;

// 3. Change iv with block
iv = i_buff_ptr;
memcpy((attribs->output)+(key->len*i),
ecb_attribs.output,
ecb_attribs.output_len);
attribs->output_len += ecb_attribs.output_len;
}
free(ecb_attribs.input);
free(ecb_attribs.output);

return Result_OK;
}

+ 12
- 0
src/enc_modes.h Wyświetl plik

@@ -0,0 +1,12 @@
#ifndef _ecb_H_
#define _ecb_H_

#include "common.h"

Result_t ecb_encrypt( CryptoAttribs_t* attribs, const Key_t* const key );
Result_t ecb_decrypt( 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 );

#endif /* _ecb_ */

+ 4
- 1
src/xor.c Wyświetl plik

@@ -1,6 +1,9 @@
#include <string.h>

void xor_repeatedly(const unsigned char* const i_xor, const unsigned i_xor_len, const unsigned char* const i_string, const unsigned i_string_len, unsigned char* o_xored)
void xor_repeatedly(
const unsigned char* const i_xor, const unsigned i_xor_len,
const unsigned char* const i_string, const unsigned i_string_len,
unsigned char* o_xored)
{
unsigned counter = 0;
while( counter < i_string_len )


+ 6
- 1
src/xor_char_finder.h Wyświetl plik

@@ -1,3 +1,6 @@
#ifndef _xor_char_finder_H_
#define _xor_char_finder_H_

#define FREQUENT_LETTERS_AMOUNT 27

struct frequency_t {
@@ -134,4 +137,6 @@ double get_frequency(char c);
void xor_char_finder(const unsigned char* const p_ciphertext_xor, struct frequency_t& o_frequency, unsigned ciphertext_len);
int crack_repeted_xor(const char* const i_hex_string, unsigned char* o_buf, const unsigned i_min_block = 3, const unsigned i_max_block = 40);
unsigned long long frequency_analysis(const unsigned char* i_text, const unsigned i_len);
int find_best_keysize(const char* i_hex_bytes, const unsigned i_len, const int i_min_keysize = 2, const int i_max_keysize = 40);
int find_best_keysize(const char* i_hex_bytes, const unsigned i_len, const int i_min_keysize = 2, const int i_max_keysize = 40);

#endif /* _xor_char_finder_ */

+ 962
- 0
suppressions.valgrind Wyświetl plik

@@ -0,0 +1,962 @@
{
<insert_a_suppression_name_here>
Memcheck:Addr8
fun:_Z21set1_challenge_7_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
fun:printf
fun:_Z21set1_challenge_7_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
fun:_Z21set1_challenge_7_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
fun:_Z21set1_challenge_7_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr1
fun:_Z21set1_challenge_7_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
fun:_Z21set1_challenge_7_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
fun:_Z21set1_challenge_7_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
fun:_Z21set1_challenge_7_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
fun:_Z21set1_challenge_7_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr2
fun:_Z21set1_challenge_7_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
fun:_Z21set1_challenge_7_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
fun:_Z19read_file_to_bufferPKcPPhb
fun:_Z21set1_challenge_7_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
fun:_Z19read_file_to_bufferPKcPPhb
fun:_Z21set1_challenge_7_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
fun:_Z19read_file_to_bufferPKcPPhb
fun:_Z21set1_challenge_7_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
fun:_Z21set1_challenge_7_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
fun:_Z21set1_challenge_7_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
fun:_Z21set1_challenge_7_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr1
fun:_Z13base64_to_hexPKhiPh
fun:_Z21set1_challenge_7_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr1
fun:_Z13base64_to_hexPKhiPh
fun:_Z21set1_challenge_7_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr1
fun:_Z13base64_to_hexPKhiPh
fun:_Z21set1_challenge_7_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr4
fun:_Z21set1_challenge_7_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr4
fun:_Z21set1_challenge_7_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr16
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
obj:/lib/x86_64-linux-gnu/libc-2.21.so
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
fun:EVP_CipherInit_ex
fun:_Z11ecb_decryptPKhjS0_jPh
fun:_Z21set1_challenge_7_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr16
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
}
{
<insert_a_suppression_name_here>
Memcheck:Addr16
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
}
{
<insert_a_suppression_name_here>
Memcheck:Addr16
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
}
{
<insert_a_suppression_name_here>
Memcheck:Addr16
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
}
{
<insert_a_suppression_name_here>
Memcheck:Addr16
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
}
{
<insert_a_suppression_name_here>
Memcheck:Addr16
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
}
{
<insert_a_suppression_name_here>
Memcheck:Addr16
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
}
{
<insert_a_suppression_name_here>
Memcheck:Addr16
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
}
{
<insert_a_suppression_name_here>
Memcheck:Addr16
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
}
{
<insert_a_suppression_name_here>
Memcheck:Addr16
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
}
{
<insert_a_suppression_name_here>
Memcheck:Addr16
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
}
{
<insert_a_suppression_name_here>
Memcheck:Addr16
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
}
{
<insert_a_suppression_name_here>
Memcheck:Addr16
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
}
{
<insert_a_suppression_name_here>
Memcheck:Addr16
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
}
{
<insert_a_suppression_name_here>
Memcheck:Addr16
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
}
{
<insert_a_suppression_name_here>
Memcheck:Addr16
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
}
{
<insert_a_suppression_name_here>
Memcheck:Addr16
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
}
{
<insert_a_suppression_name_here>
Memcheck:Addr16
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
}
{
<insert_a_suppression_name_here>
Memcheck:Addr16
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
}
{
<insert_a_suppression_name_here>
Memcheck:Addr16
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
fun:memcpy@@GLIBC_2.14
fun:EVP_DecryptUpdate
fun:_Z11ecb_decryptPKhjS0_jPh
fun:_Z21set1_challenge_7_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr1
fun:EVP_DecryptFinal_ex
fun:_Z11ecb_decryptPKhjS0_jPh
fun:_Z21set1_challenge_7_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr4
fun:_Z21set1_challenge_7_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr1
fun:strlen
fun:_Z21set1_challenge_7_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr1
fun:strlen
fun:_Z21set1_challenge_7_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr1
fun:__memcmp_sse4_1
fun:_Z21set1_challenge_7_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr1
fun:__memcmp_sse4_1
fun:_Z21set1_challenge_7_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr1
fun:__memcmp_sse4_1
fun:_Z21set1_challenge_7_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr1
fun:__memcmp_sse4_1
fun:_Z21set1_challenge_7_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
fun:_Z21set1_challenge_7_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
fun:_Z21set1_challenge_6_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
fun:printf
fun:_Z21set1_challenge_6_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr4
fun:_Z21set1_challenge_6_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
fun:_Z21set1_challenge_6_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
fun:_Z19read_file_to_bufferPKcPPhb
fun:_Z21set1_challenge_6_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
fun:_Z19read_file_to_bufferPKcPPhb
fun:_Z21set1_challenge_6_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
fun:memcpy@@GLIBC_2.14
fun:_Z19read_file_to_bufferPKcPPhb
fun:_Z21set1_challenge_6_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr2
fun:memcpy@@GLIBC_2.14
fun:_Z19read_file_to_bufferPKcPPhb
fun:_Z21set1_challenge_6_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
fun:_Z21set1_challenge_6_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
fun:_Z21set1_challenge_6_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr1
fun:_Z21set1_challenge_6_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
fun:_Z21set1_challenge_6_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr1
fun:_Z13base64_to_hexPKhiPh
fun:_Z21set1_challenge_6_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr1
fun:_Z13base64_to_hexPKhiPh
fun:_Z21set1_challenge_6_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr1
fun:_Z13base64_to_hexPKhiPh
fun:_Z21set1_challenge_6_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr1
fun:_Z13base64_to_hexPKhiPh
fun:_Z21set1_challenge_6_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr1
fun:_Z13base64_to_hexPKhiPh
fun:_Z21set1_challenge_6_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr1
fun:_Z13base64_to_hexPKhiPh
fun:_Z21set1_challenge_6_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr1
fun:_Z13base64_to_hexPKhiPh
fun:_Z21set1_challenge_6_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
fun:_Z21set1_challenge_6_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
fun:_Z21set1_challenge_6_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr1
fun:_Z21convert_hex_to_stringPKhjPc
fun:_Z21set1_challenge_6_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr1
fun:_IO_default_xsputn
fun:vfprintf
fun:vsprintf
fun:sprintf
fun:_Z21convert_hex_to_stringPKhjPc
fun:_Z21set1_challenge_6_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr1
fun:vsprintf
fun:sprintf
fun:_Z21convert_hex_to_stringPKhjPc
fun:_Z21set1_challenge_6_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr1
fun:_IO_default_xsputn
fun:_IO_padn
fun:vfprintf
fun:vsprintf
fun:sprintf
fun:_Z21convert_hex_to_stringPKhjPc
fun:_Z21set1_challenge_6_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
fun:memset
fun:_Z21set1_challenge_6_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr1
fun:strlen
fun:_Z21set1_challenge_6_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr1
fun:strlen
fun:_Z21set1_challenge_6_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr1
fun:strlen
fun:_Z17crack_repeted_xorPKcPhjj
fun:_Z17find_best_keysizePKcjii
fun:_Z21set1_challenge_6_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr1
fun:strlen
fun:_Z17crack_repeted_xorPKcPhjj
fun:_Z17find_best_keysizePKcjii
fun:_Z21set1_challenge_6_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr1
fun:strlen
fun:_Z17crack_repeted_xorPKcPhjj
fun:_Z17find_best_keysizePKcjii
fun:_Z21set1_challenge_6_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr1
fun:strlen
fun:_Z17crack_repeted_xorPKcPhjj
fun:_Z17find_best_keysizePKcjii
fun:_Z21set1_challenge_6_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr1
fun:_Z21convert_string_to_hexPKcjPh
fun:_Z17crack_repeted_xorPKcPhjj
fun:_Z17find_best_keysizePKcjii
fun:_Z21set1_challenge_6_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr1
fun:_Z21convert_string_to_hexPKcjPh
fun:_Z17crack_repeted_xorPKcPhjj
fun:_Z17find_best_keysizePKcjii
fun:_Z21set1_challenge_6_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr4
fun:_Z21set1_challenge_6_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr4
fun:_Z21set1_challenge_6_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr4
fun:_Z21set1_challenge_6_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr1
fun:_Z14xor_repeatedlyPKhjS0_jPh
fun:_Z17crack_repeted_xorPKcPhjj
fun:_Z21set1_challenge_6_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr4
fun:_Z21set1_challenge_6_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr8
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
obj:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
fun:EVP_EncryptFinal_ex
fun:_Z11ecb_encryptPKhjS0_jPh
fun:_Z11encrypt_cbcPhmS_mS_mPS_Pm
fun:_Z16cbc_enc_dec_testv
fun:_ZN4SET23runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr1
fun:strlen
fun:_Z17crack_repeted_xorPKcPhjj
fun:_Z21set1_challenge_6_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr1
fun:strlen
fun:_Z17crack_repeted_xorPKcPhjj
fun:_Z21set1_challenge_6_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr1
fun:_Z21convert_string_to_hexPKcjPh
fun:_Z17crack_repeted_xorPKcPhjj
fun:_Z21set1_challenge_6_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Addr1
fun:_Z21convert_string_to_hexPKcjPh
fun:_Z17crack_repeted_xorPKcPhjj
fun:_Z21set1_challenge_6_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: definite
fun:malloc
fun:CRYPTO_malloc
fun:EVP_CipherInit_ex
fun:_Z11ecb_decryptPKhjS0_jPh
fun:_Z21set1_challenge_7_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: definite
fun:malloc
fun:CRYPTO_malloc
fun:EVP_CipherInit_ex
fun:_Z11ecb_decryptPKhjS0_jPh
fun:_Z11decrypt_cbcPhmS_mS_mPS_Pm
fun:_Z16cbc_enc_dec_testv
fun:_ZN4SET23runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: definite
fun:malloc
fun:CRYPTO_malloc
fun:EVP_CipherInit_ex
fun:_Z11ecb_encryptPKhjS0_jPh
fun:_Z11encrypt_cbcPhmS_mS_mPS_Pm
fun:_Z16cbc_enc_dec_testv
fun:_ZN4SET23runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: definite
fun:malloc
fun:_Z11encrypt_cbcPhmS_mS_mPS_Pm
fun:_Z16cbc_enc_dec_testv
fun:_ZN4SET23runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: definite
fun:malloc
fun:getdelim
fun:_Z19read_file_to_bufferPKcPPhb
fun:_Z21set1_challenge_7_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: definite
fun:malloc
fun:_Z11decrypt_cbcPhmS_mS_mPS_Pm
fun:_Z16cbc_decrypt_testv
fun:_ZN4SET23runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: definite
fun:malloc
fun:getdelim
fun:_Z19read_file_to_bufferPKcPPhb
fun:_Z21set1_challenge_6_testv
fun:_ZN4SET13runEv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: possible
fun:malloc
fun:CRYPTO_malloc
fun:EVP_CipherInit_ex
fun:_Z11ecb_decryptPKhjS0_jPh
fun:_Z11decrypt_cbcPhmS_mS_mPS_Pm
fun:_Z16cbc_enc_dec_testv
fun:_ZN4SET23runEv
fun:main
}

+ 30
- 30
tst/utils.cpp Wyświetl plik

@@ -29,31 +29,31 @@ void hex_to_base64_test() {

memset (output,'\0', 256);
hex_to_base64(test_buff1, output, strlen(test_buff1) );
check( memcmp(expected_buff1, output, strlen(expected_buff1)) == 0 );
check( strlen(expected_buff1) == strlen(output));
CHECK( memcmp(expected_buff1, output, strlen(expected_buff1)) == 0 );
CHECK( strlen(expected_buff1) == strlen(output));

// test case when there are 2 hex'es
memset (output,'\0', 256);
hex_to_base64(test_buff2, output, strlen(test_buff2) );
check( memcmp(expected_buff2, output, strlen(expected_buff2)) == 0 );
check( strlen(expected_buff2) == strlen(output));
CHECK( memcmp(expected_buff2, output, strlen(expected_buff2)) == 0 );
CHECK( strlen(expected_buff2) == strlen(output));

// test case when there is 1 hex
memset (output,'\0', 256);
hex_to_base64(test_buff3, output, strlen(test_buff3) );
check( memcmp(expected_buff3, output, strlen(expected_buff3)) == 0 );
check( strlen(expected_buff3) == strlen(output));
CHECK( memcmp(expected_buff3, output, strlen(expected_buff3)) == 0 );
CHECK( strlen(expected_buff3) == strlen(output));

// test case when there is 1 char
memset (output,'\0', 256);
hex_to_base64(test_buff4, output, strlen(test_buff4) );
check( memcmp(expected_buff4, output, strlen(expected_buff4)) == 0 );
check( strlen(expected_buff4) == strlen(output));
CHECK( memcmp(expected_buff4, output, strlen(expected_buff4)) == 0 );
CHECK( strlen(expected_buff4) == strlen(output));

memset (output,'\0', 256);
hex_to_base64(test_buff5, output, strlen(test_buff5) );
check( memcmp(expected_buff5, output, strlen(expected_buff5)) == 0 );
check( strlen(expected_buff5) == strlen(output));
CHECK( memcmp(expected_buff5, output, strlen(expected_buff5)) == 0 );
CHECK( strlen(expected_buff5) == strlen(output));
}

void convert_string_to_hex_test()
@@ -61,14 +61,14 @@ void convert_string_to_hex_test()
const char test_buff1[] = "49276d";
unsigned char out_buff[3];
convert_string_to_hex(test_buff1, strlen(test_buff1), out_buff);
check( out_buff[0] == 0x49
CHECK( out_buff[0] == 0x49
&& out_buff[1] == 0x27
&& out_buff[2] == 0x6d);

// and back
char out_buf[6];
convert_hex_to_string(out_buff, 3, out_buf);
check( memcmp(out_buf, test_buff1, 6) == 0 );
CHECK( memcmp(out_buf, test_buff1, 6) == 0 );

}

@@ -82,7 +82,7 @@ void xor_strings_test()
xor_strings(i_buf_1, i_buf_2, buf);

convert_hex_to_string(buf, 36/2, out_buf);
check( memcmp(out_buf, "746865206b696420646f6e277420706c6179", 36) == 0);
CHECK( memcmp(out_buf, "746865206b696420646f6e277420706c6179", 36) == 0);
}

void hamming_test()
@@ -91,20 +91,20 @@ void hamming_test()
const unsigned char ch1[]="this is a test";
const unsigned char ch2[]="wokka wokka!!!";
sprintf((char*)msg, "GOT: %d", block_distance(ch1, ch2,14));
check(block_distance(ch1,ch2, 14) == 37, msg);
CHECK(block_distance(ch1,ch2, 14) == 37, msg);

const unsigned char ch3[]="test1";
const unsigned char ch4[]="test3";

sprintf((char*)msg, "GOT: %d", block_distance(ch3, ch4,5));
check(block_distance(ch3,ch4,5)==1, msg);
CHECK(block_distance(ch3,ch4,5)==1, msg);


const unsigned char ch5[]={0x01, 0x03};
const unsigned char ch6[]={0x02, 0x02};

sprintf((char*)msg, "GOT: %d", block_distance(ch5, ch6,2));
check(block_distance(ch5,ch6,2)==3, msg);
CHECK(block_distance(ch5,ch6,2)==3, msg);

}

@@ -120,22 +120,22 @@ void base64_to_hex_test()
base64_to_hex(ch2, 8, out);
base64_to_hex(ch3, 17, out3);

check( memcmp(expected, out, 6) == 0 );
check( memcmp(expected3, out3, 6) == 0 );
CHECK( memcmp(expected, out, 6) == 0 );
CHECK( memcmp(expected3, out3, 6) == 0 );
}

void c2b_test()
{
check( c2b('A') == 0 );
check( c2b('L') == 11 );
check( c2b('Z') == 25 );
check( c2b('a') == 26 );
check( c2b('z') == 51 );
check( c2b('0') == 52 );
check( c2b('5') == 57 );
check( c2b('9') == 61 );
check( c2b('+') == 62 );
check( c2b('/') == 63 );
check( c2b('=') == 64 );
check( c2b('*') == 0xFF );
CHECK( c2b('A') == 0 );
CHECK( c2b('L') == 11 );
CHECK( c2b('Z') == 25 );
CHECK( c2b('a') == 26 );
CHECK( c2b('z') == 51 );
CHECK( c2b('0') == 52 );
CHECK( c2b('5') == 57 );
CHECK( c2b('9') == 61 );
CHECK( c2b('+') == 62 );
CHECK( c2b('/') == 63 );
CHECK( c2b('=') == 64 );
CHECK( c2b('*') == 0xFF );
}

Ładowanie…
Anuluj
Zapisz