MOD2
MOD2
MODULE-2
Dr. Poornima B V
Assistant Professor,
Computer Science and Engineering,
Sahyadri College of Engineering and Management,
Adyar, Mangalore-575007.
Email: [email protected]
1
Introduction
Cryptography is the science of making information secure in the
presence of adversaries.
Cryptography is primarily used to provide a confidentiality
service.
Securing a blockchain ecosystem requires many different
cryptographic primitives, such as hash functions, symmetric key
cryptography, digital signatures, and public key cryptography.
In addition to a confidentiality service, cryptography also
provides other security services such as integrity, authentication
(entity authentication and data origin authentication), and non-
repudiation also accountability
Cryptography
Asymmetric Encryption:
Uses two keys: a public key for encryption and a private key for decryption.
Public key is shared openly, while the private key is kept secret.
It’s slower than symmetric encryption but enables secure communication
without key distribution issues.
Examples: RSA, ECC (Elliptic Curve Cryptography).
Hash Function:
Converts input data into a fixed-length string of characters (hash)
which represents the data uniquely.
It is one-way and cannot be reversed to retrieve the original input.
Used for data integrity and storing passwords securely.
Examples: SHA-256, MD5.
Cryptographic primitives
A keyless cryptographic primitive refers to cryptographic techniques or
methods that do not require the use of a secret key for their operation.
These primitives rely on other mechanisms like mathematical properties,
algorithms, or the structure of the data itself.
EX1.
Hash functions are keyless because they don't require any secret key for their
operation.
They take an input (message) and produce a fixed-size hash output (digest). The
output is meant to uniquely represent the input, and it is computationally
difficult to revert the hash back to the original input.
Examples: SHA-256, MD5, SHA-1.
Keyless Feature: Hash functions generate a unique output based solely on the
input, without any secret key.
Random Number Generation:
While some cryptographic systems require keys for random
number generation (e.g., for key generation), non-cryptographic
random number generators do not require any keys.
These can generate pseudo-random numbers based on an initial
seed value, not necessarily linked to a secret key.
Keyless Feature: The random number generation process
doesn't depend on a secret key, though it might depend on an
initial seed.
Symmetric Key Primitives
Symmetric Encryption:
•The process of encrypting data using the same key for both encryption and decryption.
•Examples:
• AES (Advanced Encryption Standard): Widely used for securing sensitive data.
• DES (Data Encryption Standard): Older, less secure than AES.
• RC4 (Rivest Cipher 4): A stream cipher, though no longer recommended due to
vulnerabilities.
Message Authentication Codes (MAC):
A MAC is used to verify both the integrity and authenticity of a message. It is a
cryptographic checksum generated by a secret key.
Examples:
HMAC (Hash-based Message Authentication Code): Combines a hash function with a
secret key to provide data integrity and authenticity.
CMAC (Cipher-based Message Authentication Code): Uses block ciphers like AES to
generate the MAC.
Stream Ciphers:
Encrypt data one bit (or byte) at a time using a key stream, which
is combined with plaintext to produce ciphertext.
There are two types of stream ciphers:
synchronous stream ciphers and asynchronous stream ciphers:
Synchronous stream ciphers are those where the keystream is
dependent only on the key.
Asynchronous stream ciphers have a keystream that is also
dependent on the encrypted data
Block Ciphers:
Encrypt data in fixed-size blocks (typically 64 or 128 bits) using
the same key for both encryption and decryption.
Block ciphers are encryption algorithms that break up the text to
be encrypted (plaintext) into blocks of a fixed length and apply
the encryption block-by-block. Block ciphers are generally built
using a design strategy known as a Feistel cipher.
A key advantage of using a Feistel cipher is that encryption and
decryption operations are almost identical and only require a
reversal of the encryption process to achieve decryption. DES is a
prime example of Feistel-based ciphers
Various modes of operation for block ciphers are Electronic Code
Book (ECB), Cipher Block Chaining (CBC), Output Feedback
(OFB) mode, and Counter (CTR) mode.
These modes are used to specify the way in which an encryption
function is applied to the plaintext.
Block encryption mode: In block encryption mode, the plaintext
is divided into blocks of fixed length depending on the type of
cipher used. Then the encryption function is applied to each
block.
Electronic Code Book (ECB) is a basic mode of operation in which
the encrypted data is produced as a result of applying the
encryption algorithm one-by-one to each block of plaintext.
In Cipher Block Chaining (CBC) mode, each block of plaintext is
XOR'd with the previously-encrypted block. CBC mode uses the
Initialization Vector (IV) to encrypt the first block. It is
recommended that the IV be randomly chosen:
The Counter (CTR) mode effectively uses a block cipher as a
stream cipher. In this case, a unique nonce is supplied that is
concatenated with the counter value to produce a keystream:
Cryptographic hash mode
Advanced Encryption Standard
During AES algorithm processing, a 4 x 4 array of bytes known as
the state is modified using multiple rounds.
Full encryption requires 10 to 14 rounds, depending on the size
of the key. The following table shows the key sizes and the
required number of rounds:
Once the state is initialized with the input to the cipher, four operations are
performed in four stages to encrypt the input. These stages are:
AddRoundKey, SubBytes, ShiftRows, and MixColumns:
1. In the AddRoundKey step, the state array is XOR'd with a subkey, which is
derived from the master key
2. SubBytes is the substitution step where a lookup table (S-box) is used to
replace all bytes of the state array
3. The ShiftRows step is used to shift each row to the left, except for the first
one, in the state array to the left in a cyclic and incremental manner
4. Finally, all bytes are mixed in the MixColumns step in a linear fashion,
column-wise
The preceding steps describe one round of AES
In the final round (either 10, 12, or 14, depending on the key
size), stage 4 is replaced with AddRoundKey to ensure that the
first three steps cannot be simply reversed.
Asymmetric Key Primitives
Digital Signatures:
•Used to authenticate the identity of the sender and ensure the integrity of the
message. The sender signs the data with their private key, and the recipient can
verify it using the sender's public key.
•Examples:
• RSA-based digital signatures.
• ECDSA (Elliptic Curve Digital Signature Algorithm): A more efficient digital
signature algorithm based on elliptic curve cryptography.
• DSA (Digital Signature Algorithm): Another algorithm used for generating
digital signatures.
A digital signature is a cryptographic technique used to verify the
authenticity of a message or document. It ensures that the
message was sent by the claimed sender and that it hasn’t been
altered during transmission.
1. Key establishment,
2. Digital signatures,
3. Identification,
4. Encryption,
5. Decryption.
Public and Private keys
Email Encryption:
Public Key: When you want to send someone an encrypted
email, you need their public key. This public key can be shared
openly.
Private Key: The recipient uses their private key to decrypt the
message. The private key is kept secret and never shared. Only
the person who owns the private key can decrypt the message.
Cryptocurrency (Bitcoin, Ethereum):
Public Key: When you want to receive cryptocurrency, you give
someone your public key (or address). This is like sharing your
bank account number.
Private Key: To access and spend your cryptocurrency, you use
your private key. This key should be kept secret, as it proves
ownership of the funds. Anyone who possesses your private key
can spend your cryptocurrency.
Mathematical functions public key cryptography algorithms
1. Integer Factorization
2. Discrete Logarithm
3. Elliptic Curves
Integer factorization
Integer factorization schemes are based on the fact that large
integers are very hard to factor. RSA is the prime example of this
type of algorithm
Integer factorization is the process of breaking down a large number into
smaller numbers (called factors) that, when multiplied together, result in the
original number.
Example: Consider the number 15. It can be broken down (factored) into two
smaller numbers: 3 and 5, because:15=3×5
Now, imagine trying to factor a really large number, say n = 123456789.
This could involve finding out which smaller numbers multiply together to give
n, which is difficult for very large numbers.
This concept is important in cryptography, particularly in RSA encryption,
where it is hard to factorize large numbers, making the encryption secure.
Discrete logarithm
A discrete logarithm scheme is based on a problem in modular arithmetic.
It is easy to calculate the result of modulo function, but it is computationally
impractical to find the exponent of the generator.
In other words, it is extremely difficult to find the input from the result. This
is a one-way function.
For example, consider the following equation: 3 pow2 mod 10 = 9
Now, given 9, the result of the preceding equation finding 2 which is the
exponent of the generator 3 in the preceding question, is extremely hard to
determine.
This difficult problem is commonly used in the Diffie Hellman key exchange
and digital signature algorithms.
Discrete Logarithm Problem
The Discrete Logarithm Problem is about solving for x in an equation like:
Where:
g is the base or generator (a number chosen in advance).
x is the exponent (the value we want to find).
p is the modulus (a number that defines the size of the numbers we're
working with).
y is the result (the output).
The Discrete Logarithm is essentially finding the exponent x given the base
g, the modulus p, and the result y.
Elliptic curves
An elliptic curve is an algebraic cubic curve over a field, which can be defined
by the following equation.
Here, a and b are integers whose values are elements of the field on which
the elliptic curve is defined. Elliptic curves can be defined over real
numbers, rational numbers, complex numbers, or finite fields.
Elliptic Curves provide a more efficient and secure way to
perform cryptographic operations.
They work by adding points on the curve and multiplying points
by scalars.
What is Elliptic Curve Cryptography (ECC)?
Elliptic Curve Cryptography relies on the elliptic curve equation:
y^2 = x^3 + ax + b where a and b are constants that define the curve.
The points on the curve form a group under a defined operation called point
addition, and this group structure is key to the security of ECC.
Point Addition:
Point addition is like adding two points on the curve to get a third point, still on
the curve.
•Imagine you have two points, P and Q, on the elliptic curve.
•To "add" them, you draw a straight line through both P and Q. This line will
intersect the curve at a third point.
•Now, you reflect this point across the x-axis, and this new reflected point is the
result of P+Q
Point Doubling:
Point doubling is a special case of point addition where you add a point
to itself.
You take a single point P on the curve and double it. In terms of
geometry, you draw the tangent line at P (a line that touches the curve
at only one point, P).
This tangent line will intersect the curve at a second point. Reflecting
that point over the x-axis gives the result of doubling the point.
Discrete logarithm problem in ECC
The discrete logarithm problem in ECC is based on the idea that, under
certain conditions, all points on an elliptic curve form a cyclic group.
On an elliptic curve, the public key is a random multiple of the generator
point, whereas the private key is a randomly chosen integer used to
generate the multiple.
In other words, a private key is a randomly selected integer, whereas the
public key is a point on the curve.
The discrete logarithm problem is used to find the private key (an
integer) where that integer falls within all points on the elliptic curve.
Consider an elliptic curve E, with two elements P and T. The discrete
logarithmic problem is to find the integer d, where 1 <= d <= #E, such
that:
Here, T is the public key (a point on the curve), and d is the private key.
#E represents the order of the elliptic curve, which means the number of points
that are present in the cyclic group of the elliptic curve.
ECC Diffie–Hellman Key Exchange
Diffie-Hellman (DH) Key Exchange is a cryptographic protocol that allows
two parties to securely exchange a shared secret over an insecure
channel without directly sharing the secret.
Key Points:
Purpose: The goal is for two parties (say, Alice and Bob) to agree on a
shared secret key that they can use to encrypt and decrypt messages,
even though their communication channel is insecure (e.g., the internet).
How It Works:
Both parties agree on some public parameters (a large prime
number and a base value).
Each party generates a private key (a secret random number),
and then they compute their public key by applying a
mathematical formula to the base and private key.
They exchange their public keys over the insecure channel.
Using their private key and the other party’s public key, both
parties can independently compute the same shared secret.
Security: The security of Diffie-Hellman relies on the difficulty of
solving the discrete logarithm problem—i.e., given a number, it’s
hard to find the exponent used to generate it.
Elliptic Curve Cryptography (ECC) uses points on a curve for
encryption.
Point Addition is adding two points to get another point on the
curve.
Point Doubling is adding a point to itself to get a new point on
the curve. These operations form the foundation of creating
secure keys and encrypting messages in ECC.
ECC Diffie–Hellman Key Exchange
Hash functions
Block size is 512-bits, and it has a word size of 32-bits. The output
is a 256-bit digest.
The compression function processes a 512-bit message block and a
256-bit intermediate hash value. There are two main components of
this function: the compression function and a message schedule.
1. Pre-processing:
1. Padding of the message is used to adjust the length of a block to
512-bits if it is smaller than the required block size of 512-bits.
2. Parsing the message into message blocks, which ensures that the
message and its padding is divided into equal blocks of 512-bits.
3. Setting up the initial hash value, which consists of the eight 32-bit
words obtained by taking the first 32-bits of the fractional parts of the
square roots of the first eight prime numbers. These initial values are
randomly chosen to initialize the process, and they provide a level of
confidence that no backdoor exists in the algorithm.
2. Hash computation:
4. Each message block is then processed in a sequence, and it requires
64 rounds to compute the full hash output. Each round uses slightly
different constants to ensure that no two rounds are the same.
5. The message schedule is prepared.
6. Eight working variables are initialized.
7. The intermediate hash value is calculated.
8. Finally, the message is processed, and the output hash is produced:
One round of a SHA-256 compression function
b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee90
hello world
88f7ace2efcde9
GeeksForGe 112e476505aab51b05aeb2246c02a11df03e1187e886f7c55d
eks 4e9935c290ade
0a979e43f4874eb24b740c0157994e34636eed0425688161c
K1t4fo0V
c58e8b26b1dcf4e
There are two primary applications of hashing:
•Password Hashes: In most website servers, it converts user passwords into a hash
value before being stored on the server. It compares the hash value re-calculated during
login to the one stored in the database for validation.
There are two primary applications of hashing:
•Integrity Verification: When it uploads a file to a website, it also shared its hash as
a bundle. When a user downloads it, it can recalculate the hash and compare it to
establish data integrity.
Merkle trees
Financial markets and trading
Financial markets enable trading of financial securities such as bonds,
equities, derivatives and currencies. There are broadly three types of
markets: money markets, credit markets, and capital markets:
Money markets: These are short-term markets where money is lent to
companies or banks to do interbank lending. Foreign exchange or FX is
another category of money markets where currencies are traded.
Credit markets: These consist mostly of retail banks where they borrow
money from central banks and loan it to companies or households in the
form of mortgages or loans.
Capital markets: These facilitate the buying and selling of financial
instruments, mainly stocks and bonds. Capital markets can be divided into
two types: primary and secondary markets. Stocks are issued directly by
the companies to investors in primary markets, whereas in secondary
markets, investors resell their securities to other investors via stock
exchanges. Various electronic trading systems are used by exchanges
today to facilitate the trading of financial instruments.
Trading
A market is a place where parties engage in exchange. It can be either a physical
location or an electronic or virtual location.
Various financial instruments, including equities, stocks, foreign exchange,
commodities, and various types of derivatives are traded at these marketplaces.
Recently, many financial institutions have introduced software platforms to
trade various types of instruments from different asset classes.
Trading can be defined as an activity in which traders buy or sell various
financial instruments to generate profit and hedge risk.
Investors, borrowers, hedgers, asset exchangers, and gamblers are a few types of
traders.
There are various ways to transact trades, such as through brokers or directly on
an exchange or Over-The-Counter (OTC) where buyers and sellers trade
directly with each other instead of using an exchange.
Brokers are agents who arrange trades for their customers. Brokers act on a
client's behalf to deal at a given price or the best possible price.