SlideShare a Scribd company logo
1 of 97
Download to read offline
Arnaud Bouchez https://synopse.info
mORMot 2
Cryptography
• Arnaud Bouchez
– Open Source Founder
• mORMot 1 and mORMot 2 
• https://github.com/synopse (e.g. SynPDF, DMustache)
– Delphi and FPC expert
• DDD, SOA, ORM, MVC
• Performance, SOLID
– Synopse & Tranquil IT
https://synopse.info https://tranquil.it
mORMot 2 Cryptography
• Introduction
• Hashes
• Encryption
• Asymmetric Cryptography
• Practical JWT
• Practical ECC
mORMot 2 Cryptography
• Introduction
• Hashes
• Encryption
• Asymmetric Cryptography
• Practical JWT
• Practical ECC
mORMot 2 Cryptography
• Disclaimer
Warning!!!!
mORMot 2 Cryptography
• Disclaimer
This is a PRACTICAL description
› not a PhD dissertation
› includes biases and reductions
› cryptography is a serious matter
mORMot 2 Cryptography
• Disclaimer
Cryptography is error prone
› the golden rule is
to not reinvent the wheel
› https://security.stackexchange.com
mORMot 2 Cryptography
• Disclaimer
Practical goals of this session
 Hashes / Encryption / Asymmetric ???
 Find in your way in mORMot source
 Understand the mORMot tests output
mORMot 2 Cryptography
• Worth saying
 Test Vectors and regression/performance tests supplied
 32-bit performance is lower (less optimized)
 Old non-AES-NI CPUs will fallback to pascal/asm version
 AARCH64 has its own static .o HW optimized code
Oldest Delphi lack of all needed asm opcodes
mORMot 2 Cryptography
• Why mORMot ?
 Used on production since years
 Audited internally by at least one 1B$ company
 Can switch to OpenSSL if needed/required
mORMot 2 Cryptography
• Why not mORMot 1 ?
mORMot 2 is a deep rewrite
 Maintainability
 Performance
 New features (1.18 as a bug-fix branch)
mORMot 2 Cryptography
• mORMot 2 Maintainability
 Units names and size
mormot.crypt.core.pas mormot.crypt.jwt.pas
mormot.crypt.ecc.pas mormot.crypt.ecc256r1.pas
mormot.crypt.openssl.pas mormot.crypt.secure.pas
mORMot 2 Cryptography
• mORMot 2 Maintainability
 Units names and size
mormot.crypt.core.pas
mormot.crypt.core.asmx64.inc
mormot.crypt.core.asmx86.inc
mORMot 2 Cryptography
• mORMot 2 Maintainability
 Units names and size
mormot.crypt.openssl.pas
mormot.lib.openssl11.pas
mORMot 2 Cryptography
• mORMot 2 Maintainability
 Units names and size
src/crypt/mormot.crypt.*
src/lib/mormot.lib.*
…
mORMot 2 Cryptography
• mORMot 2 Maintainability
 Units names and size
src/crypt/mormot.crypt.*
src/lib/mormot.lib.*
src/core/mormot.core.*
…
mORMot 2 Cryptography
• mORMot 2 Performance
 mormot.crypt.core.asmx64.inc
rewritten since 1.18
aes-ctr now faster than OpenSSL
 AARCH64 HW acceleration
aes sha2 crc32c
mORMot 2 Cryptography
• mORMot 2 Performance
 mormot.crypt.openssl.pas
OpenSSL 1.1 can be used (not 1.0)
 if available (dynamic/delayed loading on Win + POSIX)
 if faster
 for other algorithms (RSA)
 for regulatory purposes
mORMot 2 Cryptography
• Introduction
• Hashes
• Encryption
• Asymmetric Cryptography
• Practical JWT
• Practical ECC
mORMot 2 Hashes
• What is Hashing ?
• Cryptographic Hashes
• Non-Cryptographic Hashes
mORMot 2 Hashes
• What is Hashing ?
mORMot 2 Hashes
• What is Hashing ?
Algorithm Digest
mORMot 2 Hashes
• What is Hashing ?
md5 128-bit
mORMot 2 Hashes
• Cryptographic Hashes
Practical definition:
Proven Algorithm
which has no known collision
(content can’t be forged to get the same hash)
mORMot 2 Hashes
• Cryptographic Hashes
sha2 256-bit
32-bit oriented algorithm – still safe and fast
mORMot 2 Hashes
• Cryptographic Hashes
sha512 384/512-bit
64-bit oriented algorithm – used on TLS
mORMot 2 Hashes
• Cryptographic Hashes
sha3 224..512-bit
64-bit sponge algorithm – with cipher mode
mORMot 2 Hashes
• Cryptographic Hashes
 Some Algorithms require a salt and cascaded run
when used for digital signature
e.g. HMAC-SHA256 HMAC-SHA512
 Some Algorithms don’t need a double run
e.g. SHA-3
mORMot 2 Hashes
• Cryptographic Hashes
 When derivating a hash from a password/secret
 Single hashing ease brute force with dictionaries
 Rainbow tables do exist
mORMot 2 Hashes
• Cryptographic Hashes
 When derivating a hash from a password/secret
 Single hashing ease brute force with dictionaries
 Rainbow tables do exist
 Use dedicated PBKDF functions with huge rounds count
e.g. Pbkdf2HmacSha256()
 Consider a client-side challenge
(server computes a hash and let the client iterate to find a match)
mORMot 2 Hashes
• Non-Cryptographic Hashes
mORMot 2 Hashes
• Non-Cryptographic Hashes
 Collisions have been disclosed
on some Cryptographic Hashes
e.g. MD5 SHA1
 But still slow to compute (<<1GB/s)
 Not useful in practice, but for retro compatibility
mORMot 2 Hashes
• Non-Cryptographic Hashes
 32-bit general purpose hashes
 Have (a lot of) known collisions
 Are much faster (up to 20GB/s with HW opcodes)
 Are not used for authentication or fingerprint
but e.g. for a hash table (modulo table size)
or to detect transmission errors
mORMot 2 Hashes
• Non-Cryptographic Hashes
crc32 crc32c
xxhash32 BJ aesni32 32-bit
mORMot 2 Hashes
• Non-Cryptographic Hashes
 BJ = Bob Jenkins as used by Delphi RTL (slow)
 crc32 = as used in zip gzip (some HW)
 crc32c = HW opcodes in Intel/AMD/ARM
 xxhash32 … (and a lot of friends) = “fast” SW algorithms
 aesni32 = default mORMot 2 hasher
mORMot 2 Hashes
• Non-Cryptographic Hashes
 aesni32 = default mORMot 2 hasher
Hardware Accelerated on Intel/AMD (aes-ni)
Randomly seeded to avoid hash flooding
Small number of collisions (AES permutations)
Proven – used in golang RTL since years
Fallback to crc32c or xxhash32 on old CPUs
mORMot 2 Hashes
Some numbers on Intel Core i5 7300U
aes-ni pclmulqdq sse4.2 avx avx2
mORMot 2 Hashes
2500 crc32c in 225us i.e. 10.5M/s or 23 GB/s
2500 xxhash32 in 833us i.e. 2.8M/s or 6.2 GB/s
2500 crc32 in 343us i.e. 6.9M/s or 15.1 GB/s
2500 adler32 in 240us i.e. 9.9M/s or 21.6 GB/s
2500 hash32 in 447us i.e. 5.3M/s or 11.6 GB/s
2500 aesnihash in 221us i.e. 10.7M/s or 23.5 GB/s
2500 md5 in 8.29ms i.e. 294.2K/s or 641.1 MB/s
2500 sha1 in 13.75ms i.e. 177.4K/s or 386.7 MB/s
2500 hmacsha1 in 15.03ms i.e. 162.3K/s or 353.8 MB/s
2500 sha256 in 17.06ms i.e. 143.1K/s or 311.8 MB/s
2500 hmacsha256 in 18.60ms i.e. 131.2K/s or 285.9 MB/s
2500 sha384 in 11.48ms i.e. 212.5K/s or 463.2 MB/s
2500 hmacsha384 in 13.62ms i.e. 179.1K/s or 390.4 MB/s
2500 sha512 in 11.52ms i.e. 211.8K/s or 461.7 MB/s
2500 hmacsha512 in 13.62ms i.e. 179.1K/s or 390.4 MB/s
2500 sha3_256 in 26.24ms i.e. 93K/s or 202.7 MB/s
2500 sha3_512 in 47.86ms i.e. 51K/s or 111.1 MB/s
mORMot 2 Hashes
crc32c 23 GB/s xxhash32 6.2 GB/s
crc32 15.1 GB/s adler32 21.6 GB/s
hash32 11.6 GB/s aesnihash 23.5 GB/s
md5 641.1 MB/s
sha1 386.7 MB/s hmacsha1 353.8 MB/s
sha256 311.8 MB/s hmacsha256 285.9 MB/s
sha384 463.2 MB/s hmacsha384 390.4 MB/s
sha512 461.7 MB/s hmacsha512 390.4 MB/s
sha3_256 202.7 MB/s
sha3_512 111.1 MB/s Linux X86_64 FPC
mORMot 2 Hashes
crc32c 23 GB/s xxhash32 6.2 GB/s
crc32 15.1 GB/s adler32 21.6 GB/s
hash32 11.6 GB/s aesnihash 23.5 GB/s
md5 641.1 MB/s
sha1 386.7 MB/s hmacsha1 353.8 MB/s
sha256 311.8 MB/s hmacsha256 285.9 MB/s
sha384 463.2 MB/s hmacsha384 390.4 MB/s
sha512 461.7 MB/s hmacsha512 390.4 MB/s
sha3_256 202.7 MB/s
sha3_512 111.1 MB/s Linux X86_64 FPC
(with libdeflate)
mORMot 2 Hashes
• Non-Cryptographic Hashes
 Base Functions
 Direct Low-Level records
 High Level Multi-Algorithm Hasher
mORMot 2 Hashes
• Non-Cryptographic Hashes
 Base Functions
in mormot.core.base.pas
mormot.lib.z.pas
e.g. crc32c() aesnihash() xxhash32()
DefaultHasher()
crc32()
mORMot 2 Hashes
• Non-Cryptographic Hashes
 Base Functions
in mormot.core.base.pas
crc64c() crc128c() crc256c()
aesnihash64/128/256()
DefaultHasher64/128/256()
crcblock() = 4 x crc32c() for 128-bit checksums
mORMot 2 Hashes
• Non-Cryptographic Hashes
 Direct Low-Level records
in mormot.crypt.core.pas
e.g. TMD5.Init/Update/Final + MD5()
TSha256.Init/Update/Final + Sha256()
THmacSha256.Init/Update/Final …
mORMot 2 Hashes
• Non-Cryptographic Hashes
 Direct Low-Level records
why record and not class ?
 less likely to leak memory
 single purpose (easier to audit)
direct copy for thread-safe pre-computed reuse
mORMot 2 Hashes
• Non-Cryptographic Hashes
 High Level Multi-Algorithm Hasher
in mormot.crypt.secure.pas
TSignAlgo = (saSha1,
saSha256,saSha384,saSha512,
saSha3224,saSha3256,saSha3384,saSha3512,
saSha3S128,saSha3S256);
mORMot 2 Hashes
• Non-Cryptographic Hashes
 High Level Multi-Algorithm Hasher
in mormot.crypt.secure.pas
TSynSigner.Init/Update/Final/Pbkdf2
TSynHasher.Init/Update/Final
TStreamRedirect* classes
HashFile() (single or multi-algo)
mORMot 2 Cryptography
• Introduction
• Hashes
• Encryption
• Asymmetric Cryptography
• Practical JWT
• Practical ECC
mORMot 2 Encryption
Public-Key Encryption
mORMot 2 Encryption
• Advanced Encryption Standard (AES)
 NIST 2001 specification, from Rijndael algorithm
 16-byte = 128-bit block cipher
 HW accelerated (AES-NI on Intel/AMD)
 Substitution – Permutation Network Design
 Requires a Chaining Mode
mORMot 2 Encryption
Public-Key Encryption
• Advanced Encryption Standard (AES)
128/192/256 bit key
mORMot 2 Encryption
• Advanced Encryption Standard (AES)
16-byte = 128-bit block cipher = TAesBlock
 Always 128-bit blocks, even on 192/256-bit keys
 AES requires padding for the last bytes
e.g. PKCS7
(encrypted output is bigger than plain data)
mORMot 2 Encryption
• Advanced Encryption Standard (AES)
Substitution – Permutation Network Design
mORMot 2 Encryption
• Advanced Encryption Standard (AES)
Requires a Chaining Mode – never use ECB
(source: Wikipedia Block Cipher Mode of Operation)
mORMot 2 Encryption
• Advanced Encryption Standard (AES)
Requires a Chaining Mode
 Any chaining mode will need an IV
(Initialization Vector)
 May be computed from context
or supplied with the data (e.g. as trailer)
mORMot 2 Encryption
• Advanced Encryption Standard (AES)
CTR = CounTeR Mode
(wikipedia)
 Parallelizable (SIMD-friendly)
 Encryption / Decryption are Identical
mORMot 2 Encryption
• Advanced Encryption Standard (AES)
GCM = Galois/Counter Mode
 AHEAD = Encrypt and Authenticate
 128-bit digital signature with PCLMULQDQ HW acceleration
 Parallelizable (96-bit CTR)
mORMot 2 Encryption
• Advanced Encryption Standard (AES)
mormot.crypt.core.pas
Direct low-level records – not to be used in practice
 TAes record
= low-level AES/AES-NI ECB process
 TAesGcmEngine record
= low-level AES/AES-NI GCM process
mORMot 2 Encryption
• Advanced Encryption Standard (AES)
mormot.crypt.core.pas
High-Level Classes
 TAesAbstract parent class
with EncryptPkcs7/DecryptPkcs7() for cipher algos
MacEncrypt/MacAndCrypt() for AHEAD algos
 TAesEcb TAesCbc TAesCfb TAesOfb
TAesCtr TAesGcm standard/NIST modes
 TAesCfc TAesOfc TAesCtc 128-bit 4 x crc32c AHEAD
mORMot 2 Encryption
• Advanced Encryption Standard (AES)
mormot.crypt.openssl.pas
 TAesAbstract inherited classes
 TAesEcbOsl TAesCbcOsl TAesCfbOsl TAesOfbOsl
TAesCtrOsl TAesGcmOsl
mORMot 2 Encryption
• Advanced Encryption Standard (AES)
mormot.crypt.openssl.pas
 TAesAbstract inherited classes
 TAesEcbOsl TAesCbcOsl TAesCfbOsl TAesOfbOsl
TAesCtrOsl TAesGcmOsl
mORMot 2 Encryption
• Advanced Encryption Standard (AES)
mormot.crypt.core.pas
 TAesAbstract inherited classes
var
/// the fastest AES implementation classes available on the system, per mode
// - mormot.crypt.openssl may register its own classes, e.g. TAesGcmOsl
TAesFast: array[TAesMode] of TAesAbstractClass = (
TAesEcb, TAesCbc, TAesCfb, TAesOfb, TAesC64, TAesCtr,
TAesCfc, TAesOfc, TAesCtc, TAesGcm);
myaes := TAesFast[mCtr]. CreateFromPbkdf2('pwd', 'salt', 1000);
mORMot 2 Encryption
Some numbers on Intel Core i5 7300U
aes-ni pclmulqdq sse4.2 avx avx2
mORMot 2 Encryption
2500 mormot aes-128-cfb in 4.59ms i.e. 531.7K/s or 1.1 GB/s
2500 mormot aes-128-ofb in 4.53ms i.e. 538.9K/s or 1.1 GB/s
2500 mormot aes-128-c64 in 6.19ms i.e. 393.8K/s or 858.2 MB/s
2500 mormot aes-128-ctr in 1.36ms i.e. 1.7M/s or 3.8 GB/s
2500 mormot aes-128-cfc in 4.75ms i.e. 513.1K/s or 1 GB/s
2500 mormot aes-128-ofc in 5.20ms i.e. 468.8K/s or 1 GB/s
2500 mormot aes-128-ctc in 1.67ms i.e. 1.4M/s or 3.1 GB/s
2500 mormot aes-128-gcm in 2.28ms i.e. 1M/s or 2.2 GB/s
2500 mormot aes-256-cfb in 6.15ms i.e. 396.8K/s or 864.8 MB/s
2500 mormot aes-256-ofb in 6.14ms i.e. 397.6K/s or 866.5 MB/s
2500 mormot aes-256-c64 in 7.80ms i.e. 312.6K/s or 681.3 MB/s
2500 mormot aes-256-ctr in 1.76ms i.e. 1.3M/s or 2.9 GB/s
2500 mormot aes-256-cfc in 6.36ms i.e. 383.7K/s or 836.3 MB/s
2500 mormot aes-256-ofc in 6.80ms i.e. 358.8K/s or 782 MB/s
2500 mormot aes-256-ctc in 2.10ms i.e. 1.1M/s or 2.4 GB/s
2500 mormot aes-256-gcm in 2.72ms i.e. 896.9K/s or 1.9 GB/s
2500 shake128 in 27.40ms i.e. 89.1K/s or 194.1 MB/s
2500 shake256 in 26.71ms i.e. 91.3K/s or 199.1 MB/s
mORMot 2 Encryption
2500 openssl aes-128-cfb in 6.99ms i.e. 348.8K/s or 760.1 MB/s
2500 openssl aes-128-ofb in 5.21ms i.e. 468.5K/s or 1 GB/s
2500 openssl aes-128-ctr in 1.51ms i.e. 1.5M/s or 3.4 GB/s
2500 openssl aes-128-gcm in 1.88ms i.e. 1.2M/s or 2.7 GB/s
2500 openssl aes-256-cfb in 8.73ms i.e. 279.6K/s or 609.4 MB/s
2500 openssl aes-256-ofb in 6.81ms i.e. 358.2K/s or 780.7 MB/s
2500 openssl aes-256-ctr in 1.91ms i.e. 1.2M/s or 2.7 GB/s
2500 openssl aes-256-gcm in 2.28ms i.e. 1M/s or 2.2 GB/s
mORMot 2 Encryption
mORMot OpenSSL
aes-cfb 128 1.1 GB/s 0.7 GB/s
aes-cfb 256 0.8 GB/s 0.6 GB/s
aes-ctr 128 3.8 GB/s 3.4 GB/s
aes-ctr 256 2.9 GB/s 2.7 GB/s
aes-ctc 128 3.1 GB/s N/A
aes-ctc 256 2.4 GB/s N/A
aes-gcm 128 2.2 GB/s 2.7 GB/s
aes-gcm 256 1.9 GB/s 2.2 GB/s
Linux X86_64 FPC
mORMot 2 Encryption
mORMot OpenSSL
aes-cfb 128 1.1 GB/s 0.7 GB/s
aes-cfb 256 0.8 GB/s 0.6 GB/s
aes-ctr 128 3.8 GB/s 3.4 GB/s
aes-ctr 256 2.9 GB/s 2.7 GB/s
aes-ctc 128 3.1 GB/s N/A
aes-ctc 256 2.4 GB/s N/A
aes-gcm 128 2.2 GB/s 2.7 GB/s
aes-gcm 256 1.9 GB/s 2.2 GB/s
Note: No other Delphi/FPC library approaches those numbers
mORMot 2 Cryptography
• Introduction
• Hashes
• Encryption
• Asymmetric Cryptography
• Practical JWT
• Practical ECC
mORMot 2 Asymmetric Crypto
• Private/Public Keys
• Certificates and PKI
• Digital Signature
• Asymmetric Encryption
• Ephemeral Cipher
• RSA and ECC
• mormot.crypt.ecc.pas
mORMot 2 Asymmetric Crypto
• Private/Public Keys
mORMot 2 Asymmetric Crypto
• Private/Public Keys
 Public Keys can be published and shared
as files or in a common PKI storage
 Private Keys should be encrypted
with a strong password
never released
always stored in a safe place (even a real safe)
mORMot 2 Asymmetric Crypto
• Certificates and Public Key Infrastructure (PKI)
mORMot 2 Asymmetric Crypto
• Certificates and Public Key Infrastructure (PKI)
 Public Keys can be signed in chain
 Each public Key could be within a certificate
(about issuer, domain, expiration, parents…)
 Certificate chains should be easily transmitted
(e.g. as base-64 encoded files)
mORMot 2 Asymmetric Crypto
• Certificates and Public Key Infrastructure (PKI)
 mORMot features its own simple PKI
 Focused on state-of-the-art ECC 256
 Public certificates are stored in JSON files
 Small in size, but complete and easy to work with
 With a private/public key files management tool
 You can use OpenSSL standard PKI instead
mORMot 2 Asymmetric Crypto
• Digital Signature
mORMot 2 Asymmetric Crypto
• Asymmetric Encryption
mORMot 2 Asymmetric Crypto
• Ephemeral Cipher
mORMot 2 Asymmetric Crypto
• RSA and ECC
RSA – Rivest-Shamir-Adleman
challenge based on integer computation
ECC – Elliptic Curve Cryptography
compute a reverse point on curve
mORMot 2 Asymmetric Crypto
• RSA and ECC (for 128-bit security level)
key bits gen sign verify shared
RSA 3072+ 12 1K 29K -
ECC 256 60K 38K 17K 13K
OpenSSL Numbers - in operations per second
› in practice (e.g. TLS) ECC is the way to go
mORMot 2 Asymmetric Crypto
• mormot.crypt.ecc.pas
mormot.crypt.ecc256r1.pas
mormot.crypt.openssl.pas
Ecc256r1MakeKey(out pub, out priv)
Ecc256r1Sign(priv, hash, out sign)
Ecc256r1Verify(pub, hash, sign)
Ecc256r1SharedSecret(pub, priv, out secret)
mORMot 2 Asymmetric Crypto
• mormot.crypt.ecc.pas
TEccCertificate public key
TEccCertificateSecret private + public key
TEccCertificateChain PKI
TEccSignatureCertified in-mem signature
TEccSignatureCertifiedFile .sign file
mORMot 2 Asymmetric Crypto
Some numbers on Intel Core i5 7300U
aes-ni pclmulqdq sse4.2 avx avx2
mORMot 2 Asymmetric Crypto
mORMot
300 Ecc256r1MakeKey in 76.59ms i.e. 3.8K/s, aver. 255us
300 Ecc256r1Sign in 79.21ms i.e. 3.7K/s, aver. 264us
300 Ecc256r1Verify in 95.70ms i.e. 3K/s, aver. 319us
598 Ecc256r1SharedSecret in 158.93ms i.e. 3.6K/s, aver. 265us
OpenSSL
300 Ecc256r1MakeKey in 5.09ms i.e. 57.5K/s, aver. 16us
300 Ecc256r1Sign in 7.97ms i.e. 36.7K/s, aver. 26us
300 Ecc256r1Verify in 28.66ms i.e. 10.2K/s, aver. 95us
598 Ecc256r1SharedSecret in 44.75ms i.e. 13K/s, aver. 74us
mORMot 2 Asymmetric Crypto
mORMot OpenSSL
MakeKey 3.8K/s 57.5K/s
Sign 3.7K/s 36.7K/s
Verify 3K/s 10.2K/s
SharedSecret 3.6K/s 13K/s
Linux X86_64 FPC
(note: mORMot 1.18 numbers were < 1K/s
with external .o/.obj compiled with gcc)
mORMot 2 Cryptography
• Introduction
• Hashes
• Encryption
• Asymmetric Cryptography
• Practical JWT
• Practical ECC
mORMot 2 Practical JWT
• JSON Web Token (JWT)
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3O
DkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.S
flKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
(transmitted e.g. as HTTPS “Authenticate: Bearer” header)
mORMot 2 Practical JWT
• JSON Web Token (JWT)
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3O
DkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.S
flKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
(transmitted e.g. as HTTPS “Authenticate: Bearer” header)
mORMot 2 Practical JWT
• JSON Web Token (JWT)
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3O
DkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.S
flKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
{"alg": "HS256","typ": "JWT"} .{"sub":"1234567890","name":
"John Doe","iat":1516239022}.SflKxwRJSMeKKF2QT4fwpMeJf3
6POk6yJV_adQssw5c
The 3rd part is the HMAC-SHA256 of the header and payload.
mORMot 2 Practical JWT
• JSON Web Token (JWT)
mormot.crypt.jwt.pas
JWT_TEXT: array[TSignAlgo] of RawUtf8 = (
'HS256', 'HS256', 'HS384', 'HS512',
'S3224', 'S3256', 'S3384', 'S3512',
'S3S128', 'S3S256');
mORMot 2 Practical JWT
• JSON Web Token (JWT)
mormot.crypt.jwt.pas
JWT_CLASS: array[TSignAlgo] of TJwtSynSignerAbstractClass = (
TJwtHS256, TJwtHS256, TJwtHS384, TJwtHS512,
TJwtS3224, TJwtS3256, TJwtS3384, TJwtS3512,
TJwtS3S128, TJwtS3S256);
jwt := JWT_CLASS[algo].Create(
master, round, claims, [], expirationMinutes);
mORMot 2 Practical JWT
• JSON Web Token (JWT)
mormot.crypt.jwt.pas
TJwtAbstract.Compute()
TJwtAbstract.Verify()
with payload processing as JSON/TDocVariant
and TJwtES256 for ‘ES256’ (native or OpenSSL) ECC signature
mORMot 2 Practical JWT
Some numbers on Intel Core i5 7300U
aes-ni pclmulqdq sse4.2 avx avx2
mORMot 2 Practical JWT
1000 HS256 in 1.37ms i.e. 710.2K/s, aver. 1.37us
1000 HS384 in 1.44ms i.e. 673.9K/s, aver. 1.44us
1000 HS512 in 1.43ms i.e. 679.1K/s, aver. 1.43us
1000 S3224 in 1.22ms i.e. 797.8K/s, aver. 1.22us
1000 S3256 in 1.23ms i.e. 793.3K/s, aver. 1.23us
1000 S3384 in 1.23ms i.e. 792K/s, aver. 1.23us
1000 S3512 in 1.25ms i.e. 776.2K/s, aver. 1.25us
1000 S3S128 in 1.40ms i.e. 693K/s, aver. 1.40us
1000 S3S256 in 1.32ms i.e. 739.2K/s, aver. 1.32us
100 ES256 in 6.95ms i.e. 14K/s, aver. 69us
mORMot engine
mORMot 2 Practical JWT
100 RS256 in 3.57ms i.e. 27.3K/s, aver. 35us
100 RS384 in 3.57ms i.e. 27.3K/s, aver. 35us
100 RS512 in 3.58ms i.e. 27.2K/s, aver. 35us
100 PS256 in 3.78ms i.e. 25.8K/s, aver. 37us
100 PS384 in 3.71ms i.e. 26.3K/s, aver. 37us
100 PS512 in 3.67ms i.e. 26.5K/s, aver. 36us
100 ES256 in 9.38ms i.e. 10.4K/s, aver. 93us
100 ES384 in 81.22ms i.e. 1.2K/s, aver. 812us
100 ES512 in 61.65ms i.e. 1.5K/s, aver. 616us
100 ES256K in 43.32ms i.e. 2.2K/s, aver. 433us
100 EdDSA in 11.80ms i.e. 8.2K/s, aver. 118us
OpenSSL engine
mORMot 2 Cryptography
• Introduction
• Hashes
• Encryption
• Asymmetric Cryptography
• Practical JWT
• Practical ECC
mORMot 2 Practical ECC
• mORMot features
a private/public key files management tool
in the src/tools/ecc folder
Let’s play!
mORMot 2 Cryptography
any
question?

More Related Content

What's hot

Payloads in Solr - Erik Hatcher, Lucidworks
Payloads in Solr - Erik Hatcher, LucidworksPayloads in Solr - Erik Hatcher, Lucidworks
Payloads in Solr - Erik Hatcher, LucidworksLucidworks
 
Qtではじめるクロスプラットフォームアプリケーション開発 osc2019 hamanako
Qtではじめるクロスプラットフォームアプリケーション開発 osc2019 hamanakoQtではじめるクロスプラットフォームアプリケーション開発 osc2019 hamanako
Qtではじめるクロスプラットフォームアプリケーション開発 osc2019 hamanakoKazuo Asano (@kazuo_asa)
 
Introduction of eBPF - 時下最夯的Linux Technology
Introduction of eBPF - 時下最夯的Linux Technology Introduction of eBPF - 時下最夯的Linux Technology
Introduction of eBPF - 時下最夯的Linux Technology Jace Liang
 
Bidirectional Bus Modelling
Bidirectional Bus ModellingBidirectional Bus Modelling
Bidirectional Bus ModellingArrow Devices
 
汎用LoRaWANセンサノード LSN50 -V2日本語マニュアル
汎用LoRaWANセンサノード LSN50 -V2日本語マニュアル汎用LoRaWANセンサノード LSN50 -V2日本語マニュアル
汎用LoRaWANセンサノード LSN50 -V2日本語マニュアルCRI Japan, Inc.
 
Ekon24 from Delphi to AVX2
Ekon24 from Delphi to AVX2Ekon24 from Delphi to AVX2
Ekon24 from Delphi to AVX2Arnaud Bouchez
 
MySQL8.0 SYS スキーマ概要
MySQL8.0 SYS スキーマ概要MySQL8.0 SYS スキーマ概要
MySQL8.0 SYS スキーマ概要Shinya Sugiyama
 
Access Control List 1
Access Control List 1Access Control List 1
Access Control List 1Kishore Kumar
 
IOS Zone based Firewall
IOS Zone based FirewallIOS Zone based Firewall
IOS Zone based FirewallNetwax Lab
 
PostgreSQL共有バッファと関連ツール
PostgreSQL共有バッファと関連ツールPostgreSQL共有バッファと関連ツール
PostgreSQL共有バッファと関連ツールMasahiko Sawada
 
High Performance Object Pascal Code on Servers (at EKON 22)
High Performance Object Pascal Code on Servers (at EKON 22)High Performance Object Pascal Code on Servers (at EKON 22)
High Performance Object Pascal Code on Servers (at EKON 22)Arnaud Bouchez
 
“見てわかる” ファイバーチャネルSAN基礎講座(第4弾)~続・間違わない!FC SAN導入のヒントとコツ~
“見てわかる” ファイバーチャネルSAN基礎講座(第4弾)~続・間違わない!FC SAN導入のヒントとコツ~“見てわかる” ファイバーチャネルSAN基礎講座(第4弾)~続・間違わない!FC SAN導入のヒントとコツ~
“見てわかる” ファイバーチャネルSAN基礎講座(第4弾)~続・間違わない!FC SAN導入のヒントとコツ~Brocade
 
Resolving Firebird performance problems
Resolving Firebird performance problemsResolving Firebird performance problems
Resolving Firebird performance problemsAlexey Kovyazin
 
1.mysql disk io 모니터링 및 분석사례
1.mysql disk io 모니터링 및 분석사례1.mysql disk io 모니터링 및 분석사례
1.mysql disk io 모니터링 및 분석사례I Goo Lee
 
Intel AVX-512/富岳SVE用SIMDコード生成ライブラリsimdgen
Intel AVX-512/富岳SVE用SIMDコード生成ライブラリsimdgenIntel AVX-512/富岳SVE用SIMDコード生成ライブラリsimdgen
Intel AVX-512/富岳SVE用SIMDコード生成ライブラリsimdgenMITSUNARI Shigeo
 
ZabbixでDockerも監視
ZabbixでDockerも監視 ZabbixでDockerも監視
ZabbixでDockerも監視 Atsushi Tanaka
 
OSPF LSA Types Explained
OSPF LSA Types ExplainedOSPF LSA Types Explained
OSPF LSA Types ExplainedDuane Bodle
 

What's hot (20)

Payloads in Solr - Erik Hatcher, Lucidworks
Payloads in Solr - Erik Hatcher, LucidworksPayloads in Solr - Erik Hatcher, Lucidworks
Payloads in Solr - Erik Hatcher, Lucidworks
 
Qtではじめるクロスプラットフォームアプリケーション開発 osc2019 hamanako
Qtではじめるクロスプラットフォームアプリケーション開発 osc2019 hamanakoQtではじめるクロスプラットフォームアプリケーション開発 osc2019 hamanako
Qtではじめるクロスプラットフォームアプリケーション開発 osc2019 hamanako
 
Introduction of eBPF - 時下最夯的Linux Technology
Introduction of eBPF - 時下最夯的Linux Technology Introduction of eBPF - 時下最夯的Linux Technology
Introduction of eBPF - 時下最夯的Linux Technology
 
Bidirectional Bus Modelling
Bidirectional Bus ModellingBidirectional Bus Modelling
Bidirectional Bus Modelling
 
Ral by pushpa
Ral by pushpa Ral by pushpa
Ral by pushpa
 
汎用LoRaWANセンサノード LSN50 -V2日本語マニュアル
汎用LoRaWANセンサノード LSN50 -V2日本語マニュアル汎用LoRaWANセンサノード LSN50 -V2日本語マニュアル
汎用LoRaWANセンサノード LSN50 -V2日本語マニュアル
 
Ekon24 from Delphi to AVX2
Ekon24 from Delphi to AVX2Ekon24 from Delphi to AVX2
Ekon24 from Delphi to AVX2
 
MySQL8.0 SYS スキーマ概要
MySQL8.0 SYS スキーマ概要MySQL8.0 SYS スキーマ概要
MySQL8.0 SYS スキーマ概要
 
Access Control List 1
Access Control List 1Access Control List 1
Access Control List 1
 
IOS Zone based Firewall
IOS Zone based FirewallIOS Zone based Firewall
IOS Zone based Firewall
 
PostgreSQL共有バッファと関連ツール
PostgreSQL共有バッファと関連ツールPostgreSQL共有バッファと関連ツール
PostgreSQL共有バッファと関連ツール
 
Galera Cluster Best Practices for DBA's and DevOps Part 1
Galera Cluster Best Practices for DBA's and DevOps Part 1Galera Cluster Best Practices for DBA's and DevOps Part 1
Galera Cluster Best Practices for DBA's and DevOps Part 1
 
High Performance Object Pascal Code on Servers (at EKON 22)
High Performance Object Pascal Code on Servers (at EKON 22)High Performance Object Pascal Code on Servers (at EKON 22)
High Performance Object Pascal Code on Servers (at EKON 22)
 
“見てわかる” ファイバーチャネルSAN基礎講座(第4弾)~続・間違わない!FC SAN導入のヒントとコツ~
“見てわかる” ファイバーチャネルSAN基礎講座(第4弾)~続・間違わない!FC SAN導入のヒントとコツ~“見てわかる” ファイバーチャネルSAN基礎講座(第4弾)~続・間違わない!FC SAN導入のヒントとコツ~
“見てわかる” ファイバーチャネルSAN基礎講座(第4弾)~続・間違わない!FC SAN導入のヒントとコツ~
 
OSPF - Copie.pptx
OSPF - Copie.pptxOSPF - Copie.pptx
OSPF - Copie.pptx
 
Resolving Firebird performance problems
Resolving Firebird performance problemsResolving Firebird performance problems
Resolving Firebird performance problems
 
1.mysql disk io 모니터링 및 분석사례
1.mysql disk io 모니터링 및 분석사례1.mysql disk io 모니터링 및 분석사례
1.mysql disk io 모니터링 및 분석사례
 
Intel AVX-512/富岳SVE用SIMDコード生成ライブラリsimdgen
Intel AVX-512/富岳SVE用SIMDコード生成ライブラリsimdgenIntel AVX-512/富岳SVE用SIMDコード生成ライブラリsimdgen
Intel AVX-512/富岳SVE用SIMDコード生成ライブラリsimdgen
 
ZabbixでDockerも監視
ZabbixでDockerも監視 ZabbixでDockerも監視
ZabbixでDockerも監視
 
OSPF LSA Types Explained
OSPF LSA Types ExplainedOSPF LSA Types Explained
OSPF LSA Types Explained
 

Similar to Ekon25 mORMot 2 Cryptography

Cryptography for Absolute Beginners (May 2019)
Cryptography for Absolute Beginners (May 2019)Cryptography for Absolute Beginners (May 2019)
Cryptography for Absolute Beginners (May 2019)Svetlin Nakov
 
Share winter 2016 encryption
Share winter 2016 encryptionShare winter 2016 encryption
Share winter 2016 encryptionbigendiansmalls
 
视觉中国的MongoDB应用实践(QConBeijing2011)
视觉中国的MongoDB应用实践(QConBeijing2011)视觉中国的MongoDB应用实践(QConBeijing2011)
视觉中国的MongoDB应用实践(QConBeijing2011)Night Sailer
 
Digging for Android Kernel Bugs
Digging for Android Kernel BugsDigging for Android Kernel Bugs
Digging for Android Kernel BugsJiahong Fang
 
Jörg Schad - NO ONE PUTS Java IN THE CONTAINER - Codemotion Milan 2017
Jörg Schad - NO ONE PUTS Java IN THE CONTAINER - Codemotion Milan 2017Jörg Schad - NO ONE PUTS Java IN THE CONTAINER - Codemotion Milan 2017
Jörg Schad - NO ONE PUTS Java IN THE CONTAINER - Codemotion Milan 2017Codemotion
 
Gemtalk Systems Product Roadmap
Gemtalk Systems Product RoadmapGemtalk Systems Product Roadmap
Gemtalk Systems Product RoadmapESUG
 
MongoDB开发应用实践
MongoDB开发应用实践MongoDB开发应用实践
MongoDB开发应用实践iammutex
 
[CB20] Vulnerabilities of Machine Learning Infrastructure by Sergey Gordeychik
[CB20] Vulnerabilities of Machine Learning Infrastructure by Sergey Gordeychik[CB20] Vulnerabilities of Machine Learning Infrastructure by Sergey Gordeychik
[CB20] Vulnerabilities of Machine Learning Infrastructure by Sergey GordeychikCODE BLUE
 
GOD MODE Unlocked: Hardware backdoors in x86 CPUs
GOD MODE Unlocked: Hardware backdoors in x86 CPUsGOD MODE Unlocked: Hardware backdoors in x86 CPUs
GOD MODE Unlocked: Hardware backdoors in x86 CPUsPriyanka Aash
 
Cryptographic algorithms diversity: Russian (GOST) crypto algorithms
Cryptographic algorithms diversity: Russian (GOST) crypto algorithmsCryptographic algorithms diversity: Russian (GOST) crypto algorithms
Cryptographic algorithms diversity: Russian (GOST) crypto algorithmsDmitry Baryshkov
 
DEF CON 27 - JESSE MICHAEL - get off the kernel if you can't drive
DEF CON 27 - JESSE MICHAEL - get off the kernel if you can't driveDEF CON 27 - JESSE MICHAEL - get off the kernel if you can't drive
DEF CON 27 - JESSE MICHAEL - get off the kernel if you can't driveFelipe Prado
 
Encryption oracle
Encryption oracleEncryption oracle
Encryption oraclemanong007
 
Extensible Messaging and Presence Protocol (XMPP)
Extensible Messaging and Presence Protocol (XMPP)Extensible Messaging and Presence Protocol (XMPP)
Extensible Messaging and Presence Protocol (XMPP)Sean Tsai
 
DOD 2016 - Jörg Schad - Nobody Puts Java in the Conainer
DOD 2016 - Jörg Schad - Nobody Puts Java in the ConainerDOD 2016 - Jörg Schad - Nobody Puts Java in the Conainer
DOD 2016 - Jörg Schad - Nobody Puts Java in the ConainerPROIDEA
 
NSC #2 - Challenge Solution
NSC #2 - Challenge SolutionNSC #2 - Challenge Solution
NSC #2 - Challenge SolutionNoSuchCon
 
Md sal clustering internals
Md sal clustering internalsMd sal clustering internals
Md sal clustering internalsMoiz Raja
 
MongoDB for Time Series Data: Sharding
MongoDB for Time Series Data: ShardingMongoDB for Time Series Data: Sharding
MongoDB for Time Series Data: ShardingMongoDB
 
Automatic tool for static analysis
Automatic tool for static analysisAutomatic tool for static analysis
Automatic tool for static analysisChong-Kuan Chen
 
Cassandra multi-datacenter operations essentials
Cassandra multi-datacenter operations essentialsCassandra multi-datacenter operations essentials
Cassandra multi-datacenter operations essentialsJulien Anguenot
 
Intel® RDT Hands-on Lab
Intel® RDT Hands-on LabIntel® RDT Hands-on Lab
Intel® RDT Hands-on LabMichelle Holley
 

Similar to Ekon25 mORMot 2 Cryptography (20)

Cryptography for Absolute Beginners (May 2019)
Cryptography for Absolute Beginners (May 2019)Cryptography for Absolute Beginners (May 2019)
Cryptography for Absolute Beginners (May 2019)
 
Share winter 2016 encryption
Share winter 2016 encryptionShare winter 2016 encryption
Share winter 2016 encryption
 
视觉中国的MongoDB应用实践(QConBeijing2011)
视觉中国的MongoDB应用实践(QConBeijing2011)视觉中国的MongoDB应用实践(QConBeijing2011)
视觉中国的MongoDB应用实践(QConBeijing2011)
 
Digging for Android Kernel Bugs
Digging for Android Kernel BugsDigging for Android Kernel Bugs
Digging for Android Kernel Bugs
 
Jörg Schad - NO ONE PUTS Java IN THE CONTAINER - Codemotion Milan 2017
Jörg Schad - NO ONE PUTS Java IN THE CONTAINER - Codemotion Milan 2017Jörg Schad - NO ONE PUTS Java IN THE CONTAINER - Codemotion Milan 2017
Jörg Schad - NO ONE PUTS Java IN THE CONTAINER - Codemotion Milan 2017
 
Gemtalk Systems Product Roadmap
Gemtalk Systems Product RoadmapGemtalk Systems Product Roadmap
Gemtalk Systems Product Roadmap
 
MongoDB开发应用实践
MongoDB开发应用实践MongoDB开发应用实践
MongoDB开发应用实践
 
[CB20] Vulnerabilities of Machine Learning Infrastructure by Sergey Gordeychik
[CB20] Vulnerabilities of Machine Learning Infrastructure by Sergey Gordeychik[CB20] Vulnerabilities of Machine Learning Infrastructure by Sergey Gordeychik
[CB20] Vulnerabilities of Machine Learning Infrastructure by Sergey Gordeychik
 
GOD MODE Unlocked: Hardware backdoors in x86 CPUs
GOD MODE Unlocked: Hardware backdoors in x86 CPUsGOD MODE Unlocked: Hardware backdoors in x86 CPUs
GOD MODE Unlocked: Hardware backdoors in x86 CPUs
 
Cryptographic algorithms diversity: Russian (GOST) crypto algorithms
Cryptographic algorithms diversity: Russian (GOST) crypto algorithmsCryptographic algorithms diversity: Russian (GOST) crypto algorithms
Cryptographic algorithms diversity: Russian (GOST) crypto algorithms
 
DEF CON 27 - JESSE MICHAEL - get off the kernel if you can't drive
DEF CON 27 - JESSE MICHAEL - get off the kernel if you can't driveDEF CON 27 - JESSE MICHAEL - get off the kernel if you can't drive
DEF CON 27 - JESSE MICHAEL - get off the kernel if you can't drive
 
Encryption oracle
Encryption oracleEncryption oracle
Encryption oracle
 
Extensible Messaging and Presence Protocol (XMPP)
Extensible Messaging and Presence Protocol (XMPP)Extensible Messaging and Presence Protocol (XMPP)
Extensible Messaging and Presence Protocol (XMPP)
 
DOD 2016 - Jörg Schad - Nobody Puts Java in the Conainer
DOD 2016 - Jörg Schad - Nobody Puts Java in the ConainerDOD 2016 - Jörg Schad - Nobody Puts Java in the Conainer
DOD 2016 - Jörg Schad - Nobody Puts Java in the Conainer
 
NSC #2 - Challenge Solution
NSC #2 - Challenge SolutionNSC #2 - Challenge Solution
NSC #2 - Challenge Solution
 
Md sal clustering internals
Md sal clustering internalsMd sal clustering internals
Md sal clustering internals
 
MongoDB for Time Series Data: Sharding
MongoDB for Time Series Data: ShardingMongoDB for Time Series Data: Sharding
MongoDB for Time Series Data: Sharding
 
Automatic tool for static analysis
Automatic tool for static analysisAutomatic tool for static analysis
Automatic tool for static analysis
 
Cassandra multi-datacenter operations essentials
Cassandra multi-datacenter operations essentialsCassandra multi-datacenter operations essentials
Cassandra multi-datacenter operations essentials
 
Intel® RDT Hands-on Lab
Intel® RDT Hands-on LabIntel® RDT Hands-on Lab
Intel® RDT Hands-on Lab
 

More from Arnaud Bouchez

EKON27-FrameworksTuning.pdf
EKON27-FrameworksTuning.pdfEKON27-FrameworksTuning.pdf
EKON27-FrameworksTuning.pdfArnaud Bouchez
 
EKON27-FrameworksExpressiveness.pdf
EKON27-FrameworksExpressiveness.pdfEKON27-FrameworksExpressiveness.pdf
EKON27-FrameworksExpressiveness.pdfArnaud Bouchez
 
Ekon23 (2) Kingdom-Driven-Design applied to Social Media with mORMot
Ekon23 (2) Kingdom-Driven-Design applied to Social Media with mORMotEkon23 (2) Kingdom-Driven-Design applied to Social Media with mORMot
Ekon23 (2) Kingdom-Driven-Design applied to Social Media with mORMotArnaud Bouchez
 
Ekon23 (1) Kingdom-Driven-Design
Ekon23 (1) Kingdom-Driven-DesignEkon23 (1) Kingdom-Driven-Design
Ekon23 (1) Kingdom-Driven-DesignArnaud Bouchez
 
Object Pascal Clean Code Guidelines Proposal (at EKON 22)
Object Pascal Clean Code Guidelines Proposal (at EKON 22)Object Pascal Clean Code Guidelines Proposal (at EKON 22)
Object Pascal Clean Code Guidelines Proposal (at EKON 22)Arnaud Bouchez
 
Ekon21 Microservices - SOLID Meets SOA
Ekon21 Microservices - SOLID Meets SOAEkon21 Microservices - SOLID Meets SOA
Ekon21 Microservices - SOLID Meets SOAArnaud Bouchez
 
Ekon21 Microservices - Event Driven Design
Ekon21 Microservices - Event Driven DesignEkon21 Microservices - Event Driven Design
Ekon21 Microservices - Event Driven DesignArnaud Bouchez
 
Ekon20 mORMot WorkShop Delphi
Ekon20 mORMot WorkShop DelphiEkon20 mORMot WorkShop Delphi
Ekon20 mORMot WorkShop DelphiArnaud Bouchez
 
Ekon20 mORMot SOA Delphi Conference
Ekon20 mORMot SOA Delphi Conference Ekon20 mORMot SOA Delphi Conference
Ekon20 mORMot SOA Delphi Conference Arnaud Bouchez
 
Ekon20 mORMot Legacy Code Technical Debt Delphi Conference
Ekon20 mORMot Legacy Code Technical Debt Delphi Conference Ekon20 mORMot Legacy Code Technical Debt Delphi Conference
Ekon20 mORMot Legacy Code Technical Debt Delphi Conference Arnaud Bouchez
 
D1 from interfaces to solid
D1 from interfaces to solidD1 from interfaces to solid
D1 from interfaces to solidArnaud Bouchez
 
D2 domain driven-design
D2 domain driven-designD2 domain driven-design
D2 domain driven-designArnaud Bouchez
 
Delphi ORM SOA MVC SQL NoSQL JSON REST mORMot
Delphi ORM SOA MVC SQL NoSQL JSON REST mORMotDelphi ORM SOA MVC SQL NoSQL JSON REST mORMot
Delphi ORM SOA MVC SQL NoSQL JSON REST mORMotArnaud Bouchez
 

More from Arnaud Bouchez (18)

EKON27-FrameworksTuning.pdf
EKON27-FrameworksTuning.pdfEKON27-FrameworksTuning.pdf
EKON27-FrameworksTuning.pdf
 
EKON27-FrameworksExpressiveness.pdf
EKON27-FrameworksExpressiveness.pdfEKON27-FrameworksExpressiveness.pdf
EKON27-FrameworksExpressiveness.pdf
 
Ekon23 (2) Kingdom-Driven-Design applied to Social Media with mORMot
Ekon23 (2) Kingdom-Driven-Design applied to Social Media with mORMotEkon23 (2) Kingdom-Driven-Design applied to Social Media with mORMot
Ekon23 (2) Kingdom-Driven-Design applied to Social Media with mORMot
 
Ekon23 (1) Kingdom-Driven-Design
Ekon23 (1) Kingdom-Driven-DesignEkon23 (1) Kingdom-Driven-Design
Ekon23 (1) Kingdom-Driven-Design
 
Object Pascal Clean Code Guidelines Proposal (at EKON 22)
Object Pascal Clean Code Guidelines Proposal (at EKON 22)Object Pascal Clean Code Guidelines Proposal (at EKON 22)
Object Pascal Clean Code Guidelines Proposal (at EKON 22)
 
Ekon21 Microservices - SOLID Meets SOA
Ekon21 Microservices - SOLID Meets SOAEkon21 Microservices - SOLID Meets SOA
Ekon21 Microservices - SOLID Meets SOA
 
Ekon21 Microservices - Event Driven Design
Ekon21 Microservices - Event Driven DesignEkon21 Microservices - Event Driven Design
Ekon21 Microservices - Event Driven Design
 
Ekon20 mORMot WorkShop Delphi
Ekon20 mORMot WorkShop DelphiEkon20 mORMot WorkShop Delphi
Ekon20 mORMot WorkShop Delphi
 
Ekon20 mORMot SOA Delphi Conference
Ekon20 mORMot SOA Delphi Conference Ekon20 mORMot SOA Delphi Conference
Ekon20 mORMot SOA Delphi Conference
 
Ekon20 mORMot Legacy Code Technical Debt Delphi Conference
Ekon20 mORMot Legacy Code Technical Debt Delphi Conference Ekon20 mORMot Legacy Code Technical Debt Delphi Conference
Ekon20 mORMot Legacy Code Technical Debt Delphi Conference
 
2016 mORMot
2016 mORMot2016 mORMot
2016 mORMot
 
A1 from n tier to soa
A1 from n tier to soaA1 from n tier to soa
A1 from n tier to soa
 
D1 from interfaces to solid
D1 from interfaces to solidD1 from interfaces to solid
D1 from interfaces to solid
 
A3 from sql to orm
A3 from sql to ormA3 from sql to orm
A3 from sql to orm
 
A2 from soap to rest
A2 from soap to restA2 from soap to rest
A2 from soap to rest
 
D2 domain driven-design
D2 domain driven-designD2 domain driven-design
D2 domain driven-design
 
A4 from rad to mvc
A4 from rad to mvcA4 from rad to mvc
A4 from rad to mvc
 
Delphi ORM SOA MVC SQL NoSQL JSON REST mORMot
Delphi ORM SOA MVC SQL NoSQL JSON REST mORMotDelphi ORM SOA MVC SQL NoSQL JSON REST mORMot
Delphi ORM SOA MVC SQL NoSQL JSON REST mORMot
 

Recently uploaded

Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 

Recently uploaded (20)

Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 

Ekon25 mORMot 2 Cryptography

  • 2. • Arnaud Bouchez – Open Source Founder • mORMot 1 and mORMot 2  • https://github.com/synopse (e.g. SynPDF, DMustache) – Delphi and FPC expert • DDD, SOA, ORM, MVC • Performance, SOLID – Synopse & Tranquil IT https://synopse.info https://tranquil.it
  • 3. mORMot 2 Cryptography • Introduction • Hashes • Encryption • Asymmetric Cryptography • Practical JWT • Practical ECC
  • 4. mORMot 2 Cryptography • Introduction • Hashes • Encryption • Asymmetric Cryptography • Practical JWT • Practical ECC
  • 5. mORMot 2 Cryptography • Disclaimer Warning!!!!
  • 6. mORMot 2 Cryptography • Disclaimer This is a PRACTICAL description › not a PhD dissertation › includes biases and reductions › cryptography is a serious matter
  • 7. mORMot 2 Cryptography • Disclaimer Cryptography is error prone › the golden rule is to not reinvent the wheel › https://security.stackexchange.com
  • 8. mORMot 2 Cryptography • Disclaimer Practical goals of this session  Hashes / Encryption / Asymmetric ???  Find in your way in mORMot source  Understand the mORMot tests output
  • 9. mORMot 2 Cryptography • Worth saying  Test Vectors and regression/performance tests supplied  32-bit performance is lower (less optimized)  Old non-AES-NI CPUs will fallback to pascal/asm version  AARCH64 has its own static .o HW optimized code Oldest Delphi lack of all needed asm opcodes
  • 10. mORMot 2 Cryptography • Why mORMot ?  Used on production since years  Audited internally by at least one 1B$ company  Can switch to OpenSSL if needed/required
  • 11. mORMot 2 Cryptography • Why not mORMot 1 ? mORMot 2 is a deep rewrite  Maintainability  Performance  New features (1.18 as a bug-fix branch)
  • 12. mORMot 2 Cryptography • mORMot 2 Maintainability  Units names and size mormot.crypt.core.pas mormot.crypt.jwt.pas mormot.crypt.ecc.pas mormot.crypt.ecc256r1.pas mormot.crypt.openssl.pas mormot.crypt.secure.pas
  • 13. mORMot 2 Cryptography • mORMot 2 Maintainability  Units names and size mormot.crypt.core.pas mormot.crypt.core.asmx64.inc mormot.crypt.core.asmx86.inc
  • 14. mORMot 2 Cryptography • mORMot 2 Maintainability  Units names and size mormot.crypt.openssl.pas mormot.lib.openssl11.pas
  • 15. mORMot 2 Cryptography • mORMot 2 Maintainability  Units names and size src/crypt/mormot.crypt.* src/lib/mormot.lib.* …
  • 16. mORMot 2 Cryptography • mORMot 2 Maintainability  Units names and size src/crypt/mormot.crypt.* src/lib/mormot.lib.* src/core/mormot.core.* …
  • 17. mORMot 2 Cryptography • mORMot 2 Performance  mormot.crypt.core.asmx64.inc rewritten since 1.18 aes-ctr now faster than OpenSSL  AARCH64 HW acceleration aes sha2 crc32c
  • 18. mORMot 2 Cryptography • mORMot 2 Performance  mormot.crypt.openssl.pas OpenSSL 1.1 can be used (not 1.0)  if available (dynamic/delayed loading on Win + POSIX)  if faster  for other algorithms (RSA)  for regulatory purposes
  • 19. mORMot 2 Cryptography • Introduction • Hashes • Encryption • Asymmetric Cryptography • Practical JWT • Practical ECC
  • 20. mORMot 2 Hashes • What is Hashing ? • Cryptographic Hashes • Non-Cryptographic Hashes
  • 21. mORMot 2 Hashes • What is Hashing ?
  • 22. mORMot 2 Hashes • What is Hashing ? Algorithm Digest
  • 23. mORMot 2 Hashes • What is Hashing ? md5 128-bit
  • 24. mORMot 2 Hashes • Cryptographic Hashes Practical definition: Proven Algorithm which has no known collision (content can’t be forged to get the same hash)
  • 25. mORMot 2 Hashes • Cryptographic Hashes sha2 256-bit 32-bit oriented algorithm – still safe and fast
  • 26. mORMot 2 Hashes • Cryptographic Hashes sha512 384/512-bit 64-bit oriented algorithm – used on TLS
  • 27. mORMot 2 Hashes • Cryptographic Hashes sha3 224..512-bit 64-bit sponge algorithm – with cipher mode
  • 28. mORMot 2 Hashes • Cryptographic Hashes  Some Algorithms require a salt and cascaded run when used for digital signature e.g. HMAC-SHA256 HMAC-SHA512  Some Algorithms don’t need a double run e.g. SHA-3
  • 29. mORMot 2 Hashes • Cryptographic Hashes  When derivating a hash from a password/secret  Single hashing ease brute force with dictionaries  Rainbow tables do exist
  • 30. mORMot 2 Hashes • Cryptographic Hashes  When derivating a hash from a password/secret  Single hashing ease brute force with dictionaries  Rainbow tables do exist  Use dedicated PBKDF functions with huge rounds count e.g. Pbkdf2HmacSha256()  Consider a client-side challenge (server computes a hash and let the client iterate to find a match)
  • 31. mORMot 2 Hashes • Non-Cryptographic Hashes
  • 32. mORMot 2 Hashes • Non-Cryptographic Hashes  Collisions have been disclosed on some Cryptographic Hashes e.g. MD5 SHA1  But still slow to compute (<<1GB/s)  Not useful in practice, but for retro compatibility
  • 33. mORMot 2 Hashes • Non-Cryptographic Hashes  32-bit general purpose hashes  Have (a lot of) known collisions  Are much faster (up to 20GB/s with HW opcodes)  Are not used for authentication or fingerprint but e.g. for a hash table (modulo table size) or to detect transmission errors
  • 34. mORMot 2 Hashes • Non-Cryptographic Hashes crc32 crc32c xxhash32 BJ aesni32 32-bit
  • 35. mORMot 2 Hashes • Non-Cryptographic Hashes  BJ = Bob Jenkins as used by Delphi RTL (slow)  crc32 = as used in zip gzip (some HW)  crc32c = HW opcodes in Intel/AMD/ARM  xxhash32 … (and a lot of friends) = “fast” SW algorithms  aesni32 = default mORMot 2 hasher
  • 36. mORMot 2 Hashes • Non-Cryptographic Hashes  aesni32 = default mORMot 2 hasher Hardware Accelerated on Intel/AMD (aes-ni) Randomly seeded to avoid hash flooding Small number of collisions (AES permutations) Proven – used in golang RTL since years Fallback to crc32c or xxhash32 on old CPUs
  • 37. mORMot 2 Hashes Some numbers on Intel Core i5 7300U aes-ni pclmulqdq sse4.2 avx avx2
  • 38. mORMot 2 Hashes 2500 crc32c in 225us i.e. 10.5M/s or 23 GB/s 2500 xxhash32 in 833us i.e. 2.8M/s or 6.2 GB/s 2500 crc32 in 343us i.e. 6.9M/s or 15.1 GB/s 2500 adler32 in 240us i.e. 9.9M/s or 21.6 GB/s 2500 hash32 in 447us i.e. 5.3M/s or 11.6 GB/s 2500 aesnihash in 221us i.e. 10.7M/s or 23.5 GB/s 2500 md5 in 8.29ms i.e. 294.2K/s or 641.1 MB/s 2500 sha1 in 13.75ms i.e. 177.4K/s or 386.7 MB/s 2500 hmacsha1 in 15.03ms i.e. 162.3K/s or 353.8 MB/s 2500 sha256 in 17.06ms i.e. 143.1K/s or 311.8 MB/s 2500 hmacsha256 in 18.60ms i.e. 131.2K/s or 285.9 MB/s 2500 sha384 in 11.48ms i.e. 212.5K/s or 463.2 MB/s 2500 hmacsha384 in 13.62ms i.e. 179.1K/s or 390.4 MB/s 2500 sha512 in 11.52ms i.e. 211.8K/s or 461.7 MB/s 2500 hmacsha512 in 13.62ms i.e. 179.1K/s or 390.4 MB/s 2500 sha3_256 in 26.24ms i.e. 93K/s or 202.7 MB/s 2500 sha3_512 in 47.86ms i.e. 51K/s or 111.1 MB/s
  • 39. mORMot 2 Hashes crc32c 23 GB/s xxhash32 6.2 GB/s crc32 15.1 GB/s adler32 21.6 GB/s hash32 11.6 GB/s aesnihash 23.5 GB/s md5 641.1 MB/s sha1 386.7 MB/s hmacsha1 353.8 MB/s sha256 311.8 MB/s hmacsha256 285.9 MB/s sha384 463.2 MB/s hmacsha384 390.4 MB/s sha512 461.7 MB/s hmacsha512 390.4 MB/s sha3_256 202.7 MB/s sha3_512 111.1 MB/s Linux X86_64 FPC
  • 40. mORMot 2 Hashes crc32c 23 GB/s xxhash32 6.2 GB/s crc32 15.1 GB/s adler32 21.6 GB/s hash32 11.6 GB/s aesnihash 23.5 GB/s md5 641.1 MB/s sha1 386.7 MB/s hmacsha1 353.8 MB/s sha256 311.8 MB/s hmacsha256 285.9 MB/s sha384 463.2 MB/s hmacsha384 390.4 MB/s sha512 461.7 MB/s hmacsha512 390.4 MB/s sha3_256 202.7 MB/s sha3_512 111.1 MB/s Linux X86_64 FPC (with libdeflate)
  • 41. mORMot 2 Hashes • Non-Cryptographic Hashes  Base Functions  Direct Low-Level records  High Level Multi-Algorithm Hasher
  • 42. mORMot 2 Hashes • Non-Cryptographic Hashes  Base Functions in mormot.core.base.pas mormot.lib.z.pas e.g. crc32c() aesnihash() xxhash32() DefaultHasher() crc32()
  • 43. mORMot 2 Hashes • Non-Cryptographic Hashes  Base Functions in mormot.core.base.pas crc64c() crc128c() crc256c() aesnihash64/128/256() DefaultHasher64/128/256() crcblock() = 4 x crc32c() for 128-bit checksums
  • 44. mORMot 2 Hashes • Non-Cryptographic Hashes  Direct Low-Level records in mormot.crypt.core.pas e.g. TMD5.Init/Update/Final + MD5() TSha256.Init/Update/Final + Sha256() THmacSha256.Init/Update/Final …
  • 45. mORMot 2 Hashes • Non-Cryptographic Hashes  Direct Low-Level records why record and not class ?  less likely to leak memory  single purpose (easier to audit) direct copy for thread-safe pre-computed reuse
  • 46. mORMot 2 Hashes • Non-Cryptographic Hashes  High Level Multi-Algorithm Hasher in mormot.crypt.secure.pas TSignAlgo = (saSha1, saSha256,saSha384,saSha512, saSha3224,saSha3256,saSha3384,saSha3512, saSha3S128,saSha3S256);
  • 47. mORMot 2 Hashes • Non-Cryptographic Hashes  High Level Multi-Algorithm Hasher in mormot.crypt.secure.pas TSynSigner.Init/Update/Final/Pbkdf2 TSynHasher.Init/Update/Final TStreamRedirect* classes HashFile() (single or multi-algo)
  • 48. mORMot 2 Cryptography • Introduction • Hashes • Encryption • Asymmetric Cryptography • Practical JWT • Practical ECC
  • 50. mORMot 2 Encryption • Advanced Encryption Standard (AES)  NIST 2001 specification, from Rijndael algorithm  16-byte = 128-bit block cipher  HW accelerated (AES-NI on Intel/AMD)  Substitution – Permutation Network Design  Requires a Chaining Mode
  • 51. mORMot 2 Encryption Public-Key Encryption • Advanced Encryption Standard (AES) 128/192/256 bit key
  • 52. mORMot 2 Encryption • Advanced Encryption Standard (AES) 16-byte = 128-bit block cipher = TAesBlock  Always 128-bit blocks, even on 192/256-bit keys  AES requires padding for the last bytes e.g. PKCS7 (encrypted output is bigger than plain data)
  • 53. mORMot 2 Encryption • Advanced Encryption Standard (AES) Substitution – Permutation Network Design
  • 54. mORMot 2 Encryption • Advanced Encryption Standard (AES) Requires a Chaining Mode – never use ECB (source: Wikipedia Block Cipher Mode of Operation)
  • 55. mORMot 2 Encryption • Advanced Encryption Standard (AES) Requires a Chaining Mode  Any chaining mode will need an IV (Initialization Vector)  May be computed from context or supplied with the data (e.g. as trailer)
  • 56. mORMot 2 Encryption • Advanced Encryption Standard (AES) CTR = CounTeR Mode (wikipedia)  Parallelizable (SIMD-friendly)  Encryption / Decryption are Identical
  • 57. mORMot 2 Encryption • Advanced Encryption Standard (AES) GCM = Galois/Counter Mode  AHEAD = Encrypt and Authenticate  128-bit digital signature with PCLMULQDQ HW acceleration  Parallelizable (96-bit CTR)
  • 58. mORMot 2 Encryption • Advanced Encryption Standard (AES) mormot.crypt.core.pas Direct low-level records – not to be used in practice  TAes record = low-level AES/AES-NI ECB process  TAesGcmEngine record = low-level AES/AES-NI GCM process
  • 59. mORMot 2 Encryption • Advanced Encryption Standard (AES) mormot.crypt.core.pas High-Level Classes  TAesAbstract parent class with EncryptPkcs7/DecryptPkcs7() for cipher algos MacEncrypt/MacAndCrypt() for AHEAD algos  TAesEcb TAesCbc TAesCfb TAesOfb TAesCtr TAesGcm standard/NIST modes  TAesCfc TAesOfc TAesCtc 128-bit 4 x crc32c AHEAD
  • 60. mORMot 2 Encryption • Advanced Encryption Standard (AES) mormot.crypt.openssl.pas  TAesAbstract inherited classes  TAesEcbOsl TAesCbcOsl TAesCfbOsl TAesOfbOsl TAesCtrOsl TAesGcmOsl
  • 61. mORMot 2 Encryption • Advanced Encryption Standard (AES) mormot.crypt.openssl.pas  TAesAbstract inherited classes  TAesEcbOsl TAesCbcOsl TAesCfbOsl TAesOfbOsl TAesCtrOsl TAesGcmOsl
  • 62. mORMot 2 Encryption • Advanced Encryption Standard (AES) mormot.crypt.core.pas  TAesAbstract inherited classes var /// the fastest AES implementation classes available on the system, per mode // - mormot.crypt.openssl may register its own classes, e.g. TAesGcmOsl TAesFast: array[TAesMode] of TAesAbstractClass = ( TAesEcb, TAesCbc, TAesCfb, TAesOfb, TAesC64, TAesCtr, TAesCfc, TAesOfc, TAesCtc, TAesGcm); myaes := TAesFast[mCtr]. CreateFromPbkdf2('pwd', 'salt', 1000);
  • 63. mORMot 2 Encryption Some numbers on Intel Core i5 7300U aes-ni pclmulqdq sse4.2 avx avx2
  • 64. mORMot 2 Encryption 2500 mormot aes-128-cfb in 4.59ms i.e. 531.7K/s or 1.1 GB/s 2500 mormot aes-128-ofb in 4.53ms i.e. 538.9K/s or 1.1 GB/s 2500 mormot aes-128-c64 in 6.19ms i.e. 393.8K/s or 858.2 MB/s 2500 mormot aes-128-ctr in 1.36ms i.e. 1.7M/s or 3.8 GB/s 2500 mormot aes-128-cfc in 4.75ms i.e. 513.1K/s or 1 GB/s 2500 mormot aes-128-ofc in 5.20ms i.e. 468.8K/s or 1 GB/s 2500 mormot aes-128-ctc in 1.67ms i.e. 1.4M/s or 3.1 GB/s 2500 mormot aes-128-gcm in 2.28ms i.e. 1M/s or 2.2 GB/s 2500 mormot aes-256-cfb in 6.15ms i.e. 396.8K/s or 864.8 MB/s 2500 mormot aes-256-ofb in 6.14ms i.e. 397.6K/s or 866.5 MB/s 2500 mormot aes-256-c64 in 7.80ms i.e. 312.6K/s or 681.3 MB/s 2500 mormot aes-256-ctr in 1.76ms i.e. 1.3M/s or 2.9 GB/s 2500 mormot aes-256-cfc in 6.36ms i.e. 383.7K/s or 836.3 MB/s 2500 mormot aes-256-ofc in 6.80ms i.e. 358.8K/s or 782 MB/s 2500 mormot aes-256-ctc in 2.10ms i.e. 1.1M/s or 2.4 GB/s 2500 mormot aes-256-gcm in 2.72ms i.e. 896.9K/s or 1.9 GB/s 2500 shake128 in 27.40ms i.e. 89.1K/s or 194.1 MB/s 2500 shake256 in 26.71ms i.e. 91.3K/s or 199.1 MB/s
  • 65. mORMot 2 Encryption 2500 openssl aes-128-cfb in 6.99ms i.e. 348.8K/s or 760.1 MB/s 2500 openssl aes-128-ofb in 5.21ms i.e. 468.5K/s or 1 GB/s 2500 openssl aes-128-ctr in 1.51ms i.e. 1.5M/s or 3.4 GB/s 2500 openssl aes-128-gcm in 1.88ms i.e. 1.2M/s or 2.7 GB/s 2500 openssl aes-256-cfb in 8.73ms i.e. 279.6K/s or 609.4 MB/s 2500 openssl aes-256-ofb in 6.81ms i.e. 358.2K/s or 780.7 MB/s 2500 openssl aes-256-ctr in 1.91ms i.e. 1.2M/s or 2.7 GB/s 2500 openssl aes-256-gcm in 2.28ms i.e. 1M/s or 2.2 GB/s
  • 66. mORMot 2 Encryption mORMot OpenSSL aes-cfb 128 1.1 GB/s 0.7 GB/s aes-cfb 256 0.8 GB/s 0.6 GB/s aes-ctr 128 3.8 GB/s 3.4 GB/s aes-ctr 256 2.9 GB/s 2.7 GB/s aes-ctc 128 3.1 GB/s N/A aes-ctc 256 2.4 GB/s N/A aes-gcm 128 2.2 GB/s 2.7 GB/s aes-gcm 256 1.9 GB/s 2.2 GB/s Linux X86_64 FPC
  • 67. mORMot 2 Encryption mORMot OpenSSL aes-cfb 128 1.1 GB/s 0.7 GB/s aes-cfb 256 0.8 GB/s 0.6 GB/s aes-ctr 128 3.8 GB/s 3.4 GB/s aes-ctr 256 2.9 GB/s 2.7 GB/s aes-ctc 128 3.1 GB/s N/A aes-ctc 256 2.4 GB/s N/A aes-gcm 128 2.2 GB/s 2.7 GB/s aes-gcm 256 1.9 GB/s 2.2 GB/s Note: No other Delphi/FPC library approaches those numbers
  • 68. mORMot 2 Cryptography • Introduction • Hashes • Encryption • Asymmetric Cryptography • Practical JWT • Practical ECC
  • 69. mORMot 2 Asymmetric Crypto • Private/Public Keys • Certificates and PKI • Digital Signature • Asymmetric Encryption • Ephemeral Cipher • RSA and ECC • mormot.crypt.ecc.pas
  • 70. mORMot 2 Asymmetric Crypto • Private/Public Keys
  • 71. mORMot 2 Asymmetric Crypto • Private/Public Keys  Public Keys can be published and shared as files or in a common PKI storage  Private Keys should be encrypted with a strong password never released always stored in a safe place (even a real safe)
  • 72. mORMot 2 Asymmetric Crypto • Certificates and Public Key Infrastructure (PKI)
  • 73. mORMot 2 Asymmetric Crypto • Certificates and Public Key Infrastructure (PKI)  Public Keys can be signed in chain  Each public Key could be within a certificate (about issuer, domain, expiration, parents…)  Certificate chains should be easily transmitted (e.g. as base-64 encoded files)
  • 74. mORMot 2 Asymmetric Crypto • Certificates and Public Key Infrastructure (PKI)  mORMot features its own simple PKI  Focused on state-of-the-art ECC 256  Public certificates are stored in JSON files  Small in size, but complete and easy to work with  With a private/public key files management tool  You can use OpenSSL standard PKI instead
  • 75. mORMot 2 Asymmetric Crypto • Digital Signature
  • 76. mORMot 2 Asymmetric Crypto • Asymmetric Encryption
  • 77. mORMot 2 Asymmetric Crypto • Ephemeral Cipher
  • 78. mORMot 2 Asymmetric Crypto • RSA and ECC RSA – Rivest-Shamir-Adleman challenge based on integer computation ECC – Elliptic Curve Cryptography compute a reverse point on curve
  • 79. mORMot 2 Asymmetric Crypto • RSA and ECC (for 128-bit security level) key bits gen sign verify shared RSA 3072+ 12 1K 29K - ECC 256 60K 38K 17K 13K OpenSSL Numbers - in operations per second › in practice (e.g. TLS) ECC is the way to go
  • 80. mORMot 2 Asymmetric Crypto • mormot.crypt.ecc.pas mormot.crypt.ecc256r1.pas mormot.crypt.openssl.pas Ecc256r1MakeKey(out pub, out priv) Ecc256r1Sign(priv, hash, out sign) Ecc256r1Verify(pub, hash, sign) Ecc256r1SharedSecret(pub, priv, out secret)
  • 81. mORMot 2 Asymmetric Crypto • mormot.crypt.ecc.pas TEccCertificate public key TEccCertificateSecret private + public key TEccCertificateChain PKI TEccSignatureCertified in-mem signature TEccSignatureCertifiedFile .sign file
  • 82. mORMot 2 Asymmetric Crypto Some numbers on Intel Core i5 7300U aes-ni pclmulqdq sse4.2 avx avx2
  • 83. mORMot 2 Asymmetric Crypto mORMot 300 Ecc256r1MakeKey in 76.59ms i.e. 3.8K/s, aver. 255us 300 Ecc256r1Sign in 79.21ms i.e. 3.7K/s, aver. 264us 300 Ecc256r1Verify in 95.70ms i.e. 3K/s, aver. 319us 598 Ecc256r1SharedSecret in 158.93ms i.e. 3.6K/s, aver. 265us OpenSSL 300 Ecc256r1MakeKey in 5.09ms i.e. 57.5K/s, aver. 16us 300 Ecc256r1Sign in 7.97ms i.e. 36.7K/s, aver. 26us 300 Ecc256r1Verify in 28.66ms i.e. 10.2K/s, aver. 95us 598 Ecc256r1SharedSecret in 44.75ms i.e. 13K/s, aver. 74us
  • 84. mORMot 2 Asymmetric Crypto mORMot OpenSSL MakeKey 3.8K/s 57.5K/s Sign 3.7K/s 36.7K/s Verify 3K/s 10.2K/s SharedSecret 3.6K/s 13K/s Linux X86_64 FPC (note: mORMot 1.18 numbers were < 1K/s with external .o/.obj compiled with gcc)
  • 85. mORMot 2 Cryptography • Introduction • Hashes • Encryption • Asymmetric Cryptography • Practical JWT • Practical ECC
  • 86. mORMot 2 Practical JWT • JSON Web Token (JWT) eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3O DkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.S flKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c (transmitted e.g. as HTTPS “Authenticate: Bearer” header)
  • 87. mORMot 2 Practical JWT • JSON Web Token (JWT) eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3O DkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.S flKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c (transmitted e.g. as HTTPS “Authenticate: Bearer” header)
  • 88. mORMot 2 Practical JWT • JSON Web Token (JWT) eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3O DkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.S flKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c {"alg": "HS256","typ": "JWT"} .{"sub":"1234567890","name": "John Doe","iat":1516239022}.SflKxwRJSMeKKF2QT4fwpMeJf3 6POk6yJV_adQssw5c The 3rd part is the HMAC-SHA256 of the header and payload.
  • 89. mORMot 2 Practical JWT • JSON Web Token (JWT) mormot.crypt.jwt.pas JWT_TEXT: array[TSignAlgo] of RawUtf8 = ( 'HS256', 'HS256', 'HS384', 'HS512', 'S3224', 'S3256', 'S3384', 'S3512', 'S3S128', 'S3S256');
  • 90. mORMot 2 Practical JWT • JSON Web Token (JWT) mormot.crypt.jwt.pas JWT_CLASS: array[TSignAlgo] of TJwtSynSignerAbstractClass = ( TJwtHS256, TJwtHS256, TJwtHS384, TJwtHS512, TJwtS3224, TJwtS3256, TJwtS3384, TJwtS3512, TJwtS3S128, TJwtS3S256); jwt := JWT_CLASS[algo].Create( master, round, claims, [], expirationMinutes);
  • 91. mORMot 2 Practical JWT • JSON Web Token (JWT) mormot.crypt.jwt.pas TJwtAbstract.Compute() TJwtAbstract.Verify() with payload processing as JSON/TDocVariant and TJwtES256 for ‘ES256’ (native or OpenSSL) ECC signature
  • 92. mORMot 2 Practical JWT Some numbers on Intel Core i5 7300U aes-ni pclmulqdq sse4.2 avx avx2
  • 93. mORMot 2 Practical JWT 1000 HS256 in 1.37ms i.e. 710.2K/s, aver. 1.37us 1000 HS384 in 1.44ms i.e. 673.9K/s, aver. 1.44us 1000 HS512 in 1.43ms i.e. 679.1K/s, aver. 1.43us 1000 S3224 in 1.22ms i.e. 797.8K/s, aver. 1.22us 1000 S3256 in 1.23ms i.e. 793.3K/s, aver. 1.23us 1000 S3384 in 1.23ms i.e. 792K/s, aver. 1.23us 1000 S3512 in 1.25ms i.e. 776.2K/s, aver. 1.25us 1000 S3S128 in 1.40ms i.e. 693K/s, aver. 1.40us 1000 S3S256 in 1.32ms i.e. 739.2K/s, aver. 1.32us 100 ES256 in 6.95ms i.e. 14K/s, aver. 69us mORMot engine
  • 94. mORMot 2 Practical JWT 100 RS256 in 3.57ms i.e. 27.3K/s, aver. 35us 100 RS384 in 3.57ms i.e. 27.3K/s, aver. 35us 100 RS512 in 3.58ms i.e. 27.2K/s, aver. 35us 100 PS256 in 3.78ms i.e. 25.8K/s, aver. 37us 100 PS384 in 3.71ms i.e. 26.3K/s, aver. 37us 100 PS512 in 3.67ms i.e. 26.5K/s, aver. 36us 100 ES256 in 9.38ms i.e. 10.4K/s, aver. 93us 100 ES384 in 81.22ms i.e. 1.2K/s, aver. 812us 100 ES512 in 61.65ms i.e. 1.5K/s, aver. 616us 100 ES256K in 43.32ms i.e. 2.2K/s, aver. 433us 100 EdDSA in 11.80ms i.e. 8.2K/s, aver. 118us OpenSSL engine
  • 95. mORMot 2 Cryptography • Introduction • Hashes • Encryption • Asymmetric Cryptography • Practical JWT • Practical ECC
  • 96. mORMot 2 Practical ECC • mORMot features a private/public key files management tool in the src/tools/ecc folder Let’s play!