make messageheader a dataclass
This commit is contained in:
+3
-2
@@ -2,6 +2,8 @@ import os
|
||||
import pickle
|
||||
import string
|
||||
import hmac
|
||||
from dataclasses import dataclass
|
||||
|
||||
from cryptography.hazmat.primitives import hashes, serialization
|
||||
from cryptography.hazmat.primitives.asymmetric import ec
|
||||
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
|
||||
@@ -9,6 +11,7 @@ from cryptography.hazmat.primitives.kdf.hkdf import HKDF
|
||||
|
||||
CURVE = ec.SECP256R1()
|
||||
|
||||
@dataclass
|
||||
class MessageHeader:
|
||||
dh: object
|
||||
pn: int
|
||||
@@ -29,7 +32,6 @@ def KDF_RK(rk, dh_out):
|
||||
).derive(dh_out)
|
||||
return output[:32], output[32:]
|
||||
|
||||
|
||||
def KDF_CK(ck):
|
||||
return (
|
||||
hmac.new(ck, b"\x01", "sha256").digest(),
|
||||
@@ -40,7 +42,6 @@ def ENCRYPT(mk, plaintext, associated_data):
|
||||
nonce = os.urandom(12)
|
||||
return nonce + AESGCM(mk).encrypt(nonce, plaintext, associated_data)
|
||||
|
||||
|
||||
def DECRYPT(mk, ciphertext, associated_data):
|
||||
return AESGCM(mk).decrypt(ciphertext[:12], ciphertext[12:], associated_data)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user