Skip to content

Commit 52c759b

Browse files
committed
Initial commit
1 parent e61ccff commit 52c759b

File tree

242 files changed

+96316
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

242 files changed

+96316
-2
lines changed

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,14 @@ modules.order
5050
Module.symvers
5151
Mkfile.old
5252
dkms.conf
53+
54+
# Python
55+
__pycache__
56+
*.pyc
57+
58+
* CLion and/or PyCharm IDEs
59+
.idea
60+
cmake-build-debug
61+
62+
# CMake
63+
build

CMakeLists.txt

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
cmake_minimum_required(VERSION 3.4)
2+
project("mbed_AES" C)
3+
4+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -Wall")
5+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -g -O2 -Wall")
6+
7+
set(MBED_DIR mbedtls)
8+
9+
include_directories(. ${MBED_DIR})
10+
11+
# Files to build for mbedTLS crypto routines (not including all of the SSL stuff)
12+
set(MBED_CRYPTO
13+
${MBED_DIR}/aes.c
14+
${MBED_DIR}/aesni.c
15+
${MBED_DIR}/arc4.c
16+
${MBED_DIR}/asn1parse.c
17+
${MBED_DIR}/asn1write.c
18+
${MBED_DIR}/base64.c
19+
${MBED_DIR}/bignum.c
20+
${MBED_DIR}/blowfish.c
21+
${MBED_DIR}/camellia.c
22+
${MBED_DIR}/ccm.c
23+
${MBED_DIR}/cipher.c
24+
${MBED_DIR}/cipher_wrap.c
25+
${MBED_DIR}/cmac.c
26+
${MBED_DIR}/ctr_drbg.c
27+
${MBED_DIR}/des.c
28+
${MBED_DIR}/dhm.c
29+
${MBED_DIR}/ecdh.c
30+
${MBED_DIR}/ecdsa.c
31+
${MBED_DIR}/ecjpake.c
32+
${MBED_DIR}/ecp.c
33+
${MBED_DIR}/ecp_curves.c
34+
${MBED_DIR}/entropy.c
35+
${MBED_DIR}/entropy_poll.c
36+
${MBED_DIR}/error.c
37+
${MBED_DIR}/gcm.c
38+
${MBED_DIR}/havege.c
39+
${MBED_DIR}/hmac_drbg.c
40+
${MBED_DIR}/md.c
41+
${MBED_DIR}/md2.c
42+
${MBED_DIR}/md4.c
43+
${MBED_DIR}/md5.c
44+
${MBED_DIR}/md_wrap.c
45+
${MBED_DIR}/memory_buffer_alloc.c
46+
${MBED_DIR}/oid.c
47+
${MBED_DIR}/padlock.c
48+
${MBED_DIR}/pem.c
49+
${MBED_DIR}/pk.c
50+
${MBED_DIR}/pk_wrap.c
51+
${MBED_DIR}/pkcs12.c
52+
${MBED_DIR}/pkcs5.c
53+
${MBED_DIR}/pkparse.c
54+
${MBED_DIR}/pkwrite.c
55+
${MBED_DIR}/platform.c
56+
${MBED_DIR}/ripemd160.c
57+
${MBED_DIR}/rsa.c
58+
${MBED_DIR}/sha1.c
59+
${MBED_DIR}/sha256.c
60+
${MBED_DIR}/sha512.c
61+
${MBED_DIR}/threading.c
62+
${MBED_DIR}/timing.c
63+
${MBED_DIR}/version.c
64+
${MBED_DIR}/version_features.c
65+
${MBED_DIR}/xtea.c
66+
)
67+
68+
# Files to build for each executable
69+
set(AES_GCM aes_gcm.c)
70+
set(AESGCM_FILE aesgcm_file.c)
71+
set(ECDH ecdh.c)
72+
set(KDF kdf.c)
73+
set(RSA_SIGN rsa_sign.c)
74+
set(RSA_VERIFY rsa_verify.c)
75+
76+
77+
# Library type to build (uncomment one of the following lines to choose either a static or dynamic (shared) library type
78+
set(LIB_TYPE STATIC)
79+
#set(LIB_TYPE SHARED)
80+
81+
# Build mbedTLS crypto code as a library so it only builds once
82+
set(MBED_LIB mbed_crypto)
83+
add_library(${MBED_LIB} ${LIB_TYPE} ${MBED_CRYPTO})
84+
set_property(TARGET mbed_crypto PROPERTY C_STANDARD 99)
85+
86+
87+
# Executables to build
88+
set(AES_TGT aes_gcm)
89+
add_executable(${AES_TGT} ${AES_GCM})
90+
set_property(TARGET ${AES_TGT} PROPERTY C_STANDARD 99)
91+
target_link_libraries(${AES_TGT} ${MBED_LIB})
92+
93+
set(AES_FILE_TGT aesgcm_file)
94+
add_executable(${AES_FILE_TGT} ${AESGCM_FILE})
95+
set_property(TARGET ${AES_FILE_TGT} PROPERTY C_STANDARD 99)
96+
target_link_libraries(${AES_FILE_TGT} ${MBED_LIB})
97+
98+
set(ECDH_TGT ecdh)
99+
add_executable(${ECDH_TGT} ${ECDH})
100+
set_property(TARGET ${ECDH_TGT} PROPERTY C_STANDARD 99)
101+
target_link_libraries(${ECDH_TGT} ${MBED_LIB})
102+
103+
set(KDF_TGT kdf)
104+
add_executable(${KDF_TGT} ${KDF})
105+
set_property(TARGET ${KDF_TGT} PROPERTY C_STANDARD 99)
106+
target_link_libraries(${KDF_TGT} ${MBED_LIB})
107+
108+
set(RSA_SIG_TGT rsa_sign)
109+
add_executable(${RSA_SIG_TGT} ${RSA_SIGN})
110+
set_property(TARGET ${RSA_SIG_TGT} PROPERTY C_STANDARD 99)
111+
target_link_libraries(${RSA_SIG_TGT} ${MBED_LIB})
112+
113+
set(RSA_VER_TGT rsa_verify)
114+
add_executable(${RSA_VER_TGT} ${RSA_VERIFY})
115+
set_property(TARGET ${RSA_VER_TGT} PROPERTY C_STANDARD 99)
116+
target_link_libraries(${RSA_VER_TGT} ${MBED_LIB})

README.md

Lines changed: 106 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,106 @@
1-
# practical_cryptography_engineering
2-
Practical cryptography code examples using libsodium and mbedtls C libraries and Python cryptography module
1+
Practical Cryptography Engineering
2+
==================================
3+
This repository contains some practical code examples of using the following cryptograpy libraries:
4+
* [libsodium](https://github.com/jedisct1/libsodium)
5+
* A modern, portable, easy to use crypto library written in C
6+
* Focuses on providing a small number of high-quality, easy-to-use cryptographic primitives
7+
* [mbedTLS](https://github.com/ARMmbed/mbedtls)
8+
* An ultra-portable crypto library written in C which should build anywhere
9+
* Provides a wide range of cryptographic primitives
10+
* [cryptography](https://github.com/pyca/cryptography)
11+
* Python's "standard" cryptographic library which is a wrapper around [OpenSSL](https://www.openssl.org)
12+
* Provides almost all cryptographic primitives you would want in Python
13+
* [PyNaCl](https://github.com/pyca/pynacl)
14+
* Python bindings for libsodium (very partial wrapper around libsodium)
15+
* Provides a few nice cryptographic primitives not currently available in the cryptography module
16+
17+
18+
File Contents
19+
=============
20+
* aes_gcm.c
21+
* Simple self-contained C code example of using AES-256 in Galois Counter Mode (GCM) using hard-coded everything
22+
* aes_gcm_cryptography.py
23+
* Simple self-contained Python code example identical to the above
24+
* aesgcm_file.c
25+
* C code example of file-based AES-256 GCM, works with aesgcm_file.py
26+
* Takes arguments on command line and produces output to file
27+
* aesgcm_file.py
28+
* Python code example of file-based ASES-256 GCM, works with aesgcm_file.c
29+
* CMakeLists.txt
30+
* CMake file for building the mbedTLS C code projects
31+
* ecdh.c
32+
* Elliptic Curve Diffie-Hellman key exchange C code example
33+
* ecdh.py
34+
* Elliptic Curve Diffie-Hellman key exchange Python code example
35+
* kdf.c
36+
* Key Derivation Function (KDF) C code example
37+
* kdf.py
38+
* Key Derivation Function (KDF) Python code example
39+
* mbedtls
40+
* Directory containing the mbedTLS C code
41+
* rsa_signature.c
42+
* RSA Signature C code example
43+
* rsa_signature.py
44+
* RSA Signature Python code example
45+
* sodium
46+
* Directory containing libsodium examples, headers, and Windows pre-compiled library
47+
48+
49+
Building
50+
========
51+
52+
Build requires CMake and platform default C compiler installed and works on both Windows, macOS, and Linux.
53+
54+
The first stage of building is the same on all platforms:
55+
56+
```bash
57+
rm -rf build
58+
mkdir build
59+
cd build
60+
cmake ..
61+
```
62+
63+
The second stage of building is platform dependent ...
64+
65+
Linux or macOS
66+
--------------
67+
```bash
68+
make
69+
```
70+
71+
This produces the following executable files directly in the **build** directory:
72+
73+
* aes_gcm
74+
* aesgcm_file
75+
* ecdh
76+
* kdf
77+
* rsa_signature
78+
79+
Windows
80+
-------
81+
```bash
82+
devenv mbed_AES.sln /build Debug
83+
```
84+
This creates the following executable files under the **build\Debug** directory:
85+
86+
* aes_gcm.exe
87+
* aesgcm_file.exe
88+
* ecdh.exe
89+
* kdf.exe
90+
* rsa_signature.exe
91+
92+
93+
Where to learn more about cryptography
94+
======================================
95+
96+
Books
97+
-----
98+
99+
* Understading Cryptography
100+
* Cryptograpy Engineering
101+
102+
Online Courses
103+
--------------
104+
105+
* Coursera
106+
* Udacity

0 commit comments

Comments
 (0)