4.
NIP-44 Encryption Standard
NIP-44 is an encryption standard utilizing the XChaCha20-Poly1305 algorithm. This hybrid encryption system combines both symmetric and asymmetric cryptography.
4.1 ECDH (Elliptic Curve Diffie-Hellman)
ECDH is used to establish a shared secret between two parties:
Paylaşılan Nokta = sk_gönderen × pk_alıcı = sk_alıcı × pk_gönderen
Thanks to its commutative property, this operation yields the exact same point on both sides. The x-coordinate of the shared point is used as the conversation key:
conversation_key = SHA256(shared_x)
4.2 XChaCha20 Stream Cipher
XChaCha20 is an extended-nonce version of ChaCha20. It uses a 192-bit nonce, practically eliminating collision risk.
The fundamental structure of ChaCha20 is a 4x4 state matrix:
[constant constant constant constant]
[ key key key key ]
[ key key key key ]
[ nonce nonce counter counter ]
20 double rounds (20 rounds total) are run on this matrix. Each round:
1. Quarter Round: a += b; d ^= a; d <<<= 16
2. Quarter Round: c += d; b ^= c; b <<<= 12
3. Quarter Round: a += b; d ^= a; d <<<= 8
4. Quarter Round: c += d; b ^= c; b <<<= 7
These operations are applied as column rounds and diagonal rounds, then added back to the original state. The output keystream is XORed with the plaintext to produce ciphertext.
4.3 Poly1305 MAC
Poly1305 computes a MAC for a 130-bit key and 16-byte message. It operates over the prime p = 2¹³⁰ - 5:
MAC = (c₁r¹ + c₂r² + ... + cᵢrⁱ + s) mod p
Here r is the key, c₁...cᵢ are message blocks, and s is a nonce. This guarantees the integrity and authenticity of the message.
4.4 Encryption Process
The full encryption process:
1. Generate a 192-bit random nonce
2. Compute conversation_key using ECDH
3. Derive encryption_key and mac_key via HKDF
4. Encrypt plaintext using XChaCha20
5. Compute MAC using Poly1305
6. Concatenate version || nonce || ciphertext || mac