Cryptographic Primitives (2)
Cryptographic Primitives (2)
Chapter 2
Cryptographic Primitives
Generally used for encryption of small pieces of data, especially for key
transport, digital signatures, digital certificates, …
The keys generation is done by following steps :
Example with small prime numbers (in practice very large prime numbers
are needed)
We choose two prime numbers p = 3, q = 11 ;
• Their product n = 3 × 11 = 33 is the encryption module ;
• φ(n) = (3 – 1) × (11 – 1) = 2 × 10 = 20 ;
• We choose e= 3 (prime with 20) as encryption exponent;
• The decryption exponent is d = 7, the inverse of 3 modulo 20 (in effect
e . d = 3 × 7 ≡ 1 mod 20) ;
• Alice's public key is (n, e) = (33, 3), and her private key is (n, d) = (33, 7)
• Bob sends a message to Alice :
• Encryption of m = 4 by Bob with Alice's public key: 43 ≡ 31 mod 33, the
cipher is c = 31 which Bob transmits to Alice;
• Decryption of c = 31 by Alice with her private key: 317 ≡ 4 mod 33,
Alice finds the initial message m = 4.
Asymmetric cryptosystem : Diffie–Hellman key exchange
Main
• Alice chooses a large random number a (kpr,A) such that 1<a<p −1 and
calculates A = ga mod p (kpub,A)
• Bob chooses another large random number b (kpr,B) such that 1<b<p −1
and calculates B = gb mod p (kpub,B)
• Alice sends A to Bob and Bob sends B to Alice.
• Alice calculates kA,B = Ba mod p
• Bob calculates kA,B = Ab mod p
Asymmetric cryptosystem : Diffie–Hellman key exchange
Elliptic curves are cubic (x3) mathematic equations, in contrast to ellipse which is
formed by quadratic curves (x2). The elliptic curves have favorable characteristics,
and especially the X-axis symmetry, in the field of cryptography and therefore in
security
Elliptic Curve Cryptography (ECC) provides the same level of security as RSA or
discrete logarithm systems with considerably shorter operands (e.g. 160–256 bit vs.
1024–3072 bit).
ECC is based on the generalized discrete logarithm (DL) problem, and thus DL-
protocols such as the Diffie–Hellman key exchange can also be realized using elliptic
curves. Bitcoin uses ECC as its public key cryptosystem.
Elliptic curve
The elliptic curve over Zp , p > 3, is the set of all pairs (x,y) Zp
which fulfill
y2 = x3 + ax + b mod p
together with an imaginary or abstract point at infinity Ϭ, where
a,b Zp
and the condition 4a3 + 27 b2 ≠ 0 mod p
Asymmetric cryptosystem : Elliptic Curve
The ECC is a great technique to generate the keys, but is used along
side other techniques for digital signatures and key exchange.
For example, ECC is quite popularly used for key exchange (ECDH )
and digital signatures (ECDSA).
The ECDSA is an important cryptographic component in Bitcoin and
Ethereum blockchains.
The private key in ECC is integer and it’s length depends on the
underlying curve.
In most applications (Like OpenSSL, OpenSSH, Bitcoin and Ethereum)
the default key length for the ECC private keys is 256 bits : secp256k1.
Depending on the curve many different ECC key sizes are possible :192-
bit (curve secp192r1), 233-bit (curve sect233k1), 224-bit (curve
secp224k1), 256-bit (curves secp256k1 and Curve25519), 283-bit (curve
sect283k1), 384-bit (curves p384 and secp384r1), …
Elliptic curve Diffie–Hellman key exchange
Cryptographic Hash function
Hash function is a form of cryptographic scheme but they are not the
same : They are interrelated concepts.
Hash function is an integral part of blockchain technology.
It is a mathematical function H or algorithm that maps data M of
arbitrary size of m bits (m is variable) to a bit array hash value or
digest h of n bits (n is fixe).
H(M) = h ; m << n
H is a one-way function , which is practically infeasible to invert.
Cryptographic Hash function
Source http://valerieaurora.org/hash.html
Cryptographic Hash function Example: SHA-1
SHA-1 produces a 160-bit message digest output. Before the hash computation, the
algorithm has to preprocess the message.
The compression function processes the message in 512-bit chunks. The
compression function consists of 80 rounds which are divided into four stages of 20
rounds each.
• Preprocessing : Before the actual hash computation, the message x has to be
padded to fit a size of a multiple of 512 bit. For the internal processing, the padded
message must then be divided into blocks. Also, the initial value H0 is set to a
predefined constant
Padding : l is the length of the message x
Cryptographic Hash function : SHA-1
Initial value H0 : A 160-bit buffer is used to hold the initial hash value for the first
iteration. The five 32-bit words are fixed and given in hexadecimal notation as:
Cryptographic Hash function : SHA-1
Where X≪n indicates a circular left shift of the word X by n bit positions.
• Five working registers of size of 32 bits A,B,C,D,E.
• A hash value Hi consisting of five 32-bit words
The four SHA-1 stages have a similar structure but use different internal
functions ft and stage-dependent constants Kt, where 1 ≤ t ≤ 4.
The output after 80 rounds is added to the input value Hi−1 modulo 232 .
According to the table and depending on the stage every 20 rounds a new
function and a new constant are being used.
Cryptographic Hash function : SHA-1 Round
Digital Signature
Bob wants to send a message to Alice. Although it is not important that the
message be kept secret, he wants Alice to be certain that the message is indeed
from him.
Bob uses a secure hash function, such as SHA-512, to generate a hash value for
the message.
The hash value, together with Bob’s private key serves as input to a digital
signature generation algorithm, which produces a short block that functions as a
digital signature.
Bob sends the message with the signature attached.
When Alice receives the message plus signature, she calculates a hash value for
the message; provides the hash value and Bob’s public key as inputs to a digital
signature verification algorithm.
If the algorithm returns the result that the signature is valid, Alice is assured
that the message must have been signed by Bob.
No one else has Bob’s private key and therefore no one else could have created a
signature that could be verified for this message with Bob’s public key. It is
impossible to alter the message without access to Bob’s private key, so the
message is authenticated both in terms of source and in terms of data integrity.
Digital Signature with Hash
Key generation : Key generation in the RSA digital signature scheme is exactly
the same as key generation in the RSA cryptosystem.
Signing : Alice creates a signature out of the message using her private exponent,
S = Md mod n and sends the message and the signature to Bob.
Verifying : Bob receives M and S. Bob applies Alice’s public exponent to the
signature to create a copy of the message M′ = Se mod n. Bob compares the value
of M′ with the value of M. If the two values are congruent, Bob accepts the
message.
RSA Digital Signature Example
M ≡ M′ mod n