đź‘®
Contract Cops
  • Mastering Ethereum Book
    • What is ethereum?
    • Tokens
    • Oracles
    • Decenralized Applications(DApps)
    • The Ethereum virtual machine
    • Ethereum basics
    • Ethereum clients
    • Cryptography
    • Wallets
    • Transactions
    • Chapter 7 - Smart Contracts & Solidity
    • Side Notes
      • Tokens
      • Smart Contracts and Solidity
  • Cryptography
    • Ethereum Cryptography - Cheatsheet
    • Assymetric vs symmetric cryptography
    • ECDSA vs RSA
    • Elliptic curves and ECDSA
    • Sha-256 Example
    • Sha-256
    • What are the different steps in SHA-256?
  • Ethereum Blocks
    • Block Headers
  • Learning Solidity
    • Storage vs memory
    • Upgradeable contracts
      • Proxy pattern in smart contracts
  • PoS
    • Proof of stake
  • PoW
    • PoW
  • Tokens
    • ERC-1155
    • ERC20
  • Cryptonomics
    • Automated market makers
    • Collateral Tokens
    • Collateralized Stablecoin
    • Fiat currency
    • Liquidity pool
    • Open Position: Meaning and Risk in Trading
    • Slippage
    • Spot price
  • Common Attack Vectors
    • Checking access control
    • Access control issues on critical functions
    • Account Existence Check for low level calls
    • Account Existence Check
    • Common attacks with contract/EOA addresses
    • Arithmetic under/overflow
    • Assert Attack
    • Assert require revert
    • Assert Violation
    • Bad Interface DOS
    • Bad pragma and compiler
    • Block Timestamp Manipulation
    • Bypassing contract check
    • Code With No Effects
    • Code size check vulnerability
    • Constructors with Care
    • Default Visibilities
    • Delegatecall
    • Delegatecall
    • Denial of Service (DoS)
    • DoS with block gas limit
    • Entropy Illusion
    • External contract referencing
    • Flash Loan Attack
    • Floating Point and Precision
    • Function selector abuse
    • Function selector abuse
    • Smart contract gas griefing
    • Hash collision parameters
    • Hash Collisions With Multiple Variable Length Arguments
    • Imprecise arithmetic
    • Improper Array Deletion
    • Incorrect array deletion
    • Incorrect interface
    • Insufficient Gas Griefing
    • Loop through long arrays
    • Message call with hardcoded gas amount
    • Not enough gas for ether transfer
    • Precision Loss in Calculations
    • Oracle Manipulation
    • Public Burn Function
    • Read-only reentrancy
    • Race Conditions/Front Running
    • Reentrancy Attacks
    • Reentrancy
    • Requirement Violation
    • Right-To-Left-Override control character (U+202E)
    • Shadowing State Variables
    • Short Address / Parameter attack
    • Signature Malleability
    • Signature Replay
    • Transaction Order Dependence
    • Tx.Origin Authentication
    • Unchecked CALL Return Values
    • Unexpected ether
    • Uninitialized Storage Pointers
    • Unsafe Ownership Transfer
  • EIP's
    • EIP155
    • EIP55
  • PoW
    • Ethash
    • Scrypt - RFC 7914
  • Questions for self evaluation
    • Questions 23/04/2023 (Nr: 84)
    • Usability guide for questions
  • Frequently asked questions
    • What is the difference between transaction and message?
    • What is the use of a interface or function without implementation?
  • UsefulResources
Powered by GitBook
On this page
  1. Cryptography

Assymetric vs symmetric cryptography

Symmetric encryptionâť— Symmetric key encryption is a type of encryption where there is only secret key that is being passed around together with the encrypted data âť—Symmetric algorithms are also known as secret key algorithmsImagine you want to send a message to someone, but you do not want to reveal the contents of that message. By using symmetric encryption, the data is "encrypted" with a certain algorithm which can then be decrypted using only a special private key.The secret key, used by the communicating entities may be in any form - number, string, or both.âť— They have to be achieved using an RNG (Random number generator). For banking-grade encryption or similar, an RNG must be used that is up to industry standards, for example FIPS 140-2

What is a cipher?A cipher is a type of algorithm that takes in a plaintext input and a key and encrypts it. The way that ciphers work can vary a lot (some can be very complex and some may be quite simple.) The key does not have to be a set of characters or numbers, but it can be a set of actions that must happen.âť— For example, we imagine a message, "Attack the king" and a key "Rotate every letter by 13 places to the right"

Types of symmetric algorithms<b> Block algorithms (block ciphers)âť— Block ciphers (as the name suggests) are encryption algorithms where the input data is encrypted in blocks, rather than bit by bit. Usually, the size of the blocks is fixed, but most standards are 64 bits to 128 bits.Some of the most important and popular symmetric cipher algorithms are DES and AESâť— DES: Data encryption standard. The blocks are of size 64 bits and the keys are of size 56 bits. This is no longer a standard since they are too easy to decrypt and easy to brute-forceâť— AES: Advanced encryption standardBlocks of 128 bits are encrypted/decrypted and keys of sizes 128 bits, 192 or 256 bits.Block ciphers require an IV (initialization vector) that is added to the input to increase the keyspace of the cipher and make it more difficult to decode. The IV is derived from an RNG, which is combined with the first block's text to ensure all of the other blocks result in ciphertext that isn't the same.<b> Stream algorithms (stream ciphers)âť— Stream ciphers are encryption algorithms, where unlike the block ciphers, they work by encrypting bit by bitThe key for stream ciphers can be combined together with the data, desired to be encrypted.Some examples are Chacha20 or RC4 (too weak to use)

Where is symmetric encryption used?Unlike asymmetric encryption, symmetric is much faster. It is also much more efficient and less CPU use.âť— Since symmetric encryption is generally faster and more efficient, it is used to encrypt lots of bulk data - suck as database encryptionSymmetric encryption is used in hashing, random number generation and payment applications/validations

Assymetric encryptionâť— Assymetric encryption (also known as public key encryption) is a type of encryption where there are two keys available. One of those keys is public and the other one is privatePrivate keys can be generated in varying ways. In ethereum, private keys are very long, randomly generated numbers. Then, an assymetric algorithm (namely ECDSA) is used to encrypt the private key and derive a public key.âť— Assymetric encryption is hundreds of times slower than symmetric encryption. The reason why assymetric encryption is often referred as "more safe" is that there is no key that is constantly being transfered with every message/transaction.The keys are mathematically connectedYou can derive a public key from a private key but not the other way aroundâť— Important note as example: The trapdoor function

Differences between the two types of encryption

PreviousEthereum Cryptography - CheatsheetNextECDSA vs RSA

Last updated 2 years ago