mirror of
https://github.com/codex-storage/nim-codex-dht.git
synced 2025-02-13 12:26:34 +00:00
encoding: introducing type cipher=aes128
Introducing the cipher type to ease changing cipher. No functional change Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
parent
316464fc71
commit
f766cb39b1
@ -40,6 +40,9 @@ declareCounter discovery_session_decrypt_failures, "Session decrypt failures"
|
||||
logScope:
|
||||
topics = "discv5"
|
||||
|
||||
type
|
||||
cipher = aes128
|
||||
|
||||
const
|
||||
version: uint16 = 1
|
||||
idSignatureText = "discovery v5 identity proof"
|
||||
@ -162,7 +165,7 @@ proc deriveKeys*(n1, n2: NodeId, priv: PrivateKey, pub: PublicKey,
|
||||
ok secrets
|
||||
|
||||
proc encryptGCM*(key: AesKey, nonce, pt, authData: openArray[byte]): seq[byte] =
|
||||
var ectx: GCM[aes128]
|
||||
var ectx: GCM[cipher]
|
||||
ectx.init(key, nonce, authData)
|
||||
result = newSeq[byte](pt.len + gcmTagSize)
|
||||
ectx.encrypt(pt, result)
|
||||
@ -175,7 +178,7 @@ proc decryptGCM*(key: AesKey, nonce, ct, authData: openArray[byte]):
|
||||
debug "cipher is missing tag", len = ct.len
|
||||
return
|
||||
|
||||
var dctx: GCM[aes128]
|
||||
var dctx: GCM[cipher]
|
||||
dctx.init(key, nonce, authData)
|
||||
var res = newSeq[byte](ct.len - gcmTagSize)
|
||||
var tag: array[gcmTagSize, byte]
|
||||
@ -189,7 +192,7 @@ proc decryptGCM*(key: AesKey, nonce, ct, authData: openArray[byte]):
|
||||
return some(res)
|
||||
|
||||
proc encryptHeader*(id: NodeId, iv, header: openArray[byte]): seq[byte] =
|
||||
var ectx: CTR[aes128]
|
||||
var ectx: CTR[cipher]
|
||||
ectx.init(id.toByteArrayBE().toOpenArray(0, 15), iv)
|
||||
result = newSeq[byte](header.len)
|
||||
ectx.encrypt(header, result)
|
||||
@ -374,7 +377,7 @@ proc decodeHeader*(id: NodeId, iv, maskedHeader: openArray[byte]):
|
||||
DecodeResult[(StaticHeader, seq[byte])] =
|
||||
# No need to check staticHeader size as that is included in minimum packet
|
||||
# size check in decodePacket
|
||||
var ectx: CTR[aes128]
|
||||
var ectx: CTR[cipher]
|
||||
ectx.init(id.toByteArrayBE().toOpenArray(0, aesKeySize - 1), iv)
|
||||
# Decrypt static-header part of the header
|
||||
var staticHeader = newSeq[byte](staticHeaderSize)
|
||||
|
Loading…
x
Reference in New Issue
Block a user