Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/naxolotl/naxolotl.nim
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ type Doubleratchet* = object
# TODO: SkippedKeys
skippedMessageKeys: Table[(PublicKey,MsgCount), MessageKey]

const DomainSepKdfRoot = "DoubleRatchet"
const DomainSepKdfMsg = "MessageKey"
const DomainSepKdfChain = "ChainKey"

const DomainSepKdfRoot = "DoubleRatchetRootKey"


type DrHeader* = object
Expand Down Expand Up @@ -68,8 +65,8 @@ func kdfRoot(self: var Doubleratchet, rootKey: RootKey, dhOutput:DhDerivedKey):

func kdfChain(self: Doubleratchet, chainKey: ChainKey): (MessageKey, ChainKey) =

let msgKey = hkdfExtract(chainKey, [0x01u8], cast[seq[byte]](DomainSepKdfMsg))
let chainKey = hkdfExtract(chainKey, [0x02u8], cast[seq[byte]](DomainSepKdfChain))
let msgKey = hkdfExtract(chainKey, [0x01u8])
let chainKey = hkdfExtract(chainKey, [0x02u8])

return(msgKey, chainKey)

Expand Down
4 changes: 2 additions & 2 deletions src/naxolotl/utils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import errors
import types


func hkdfExtract*(salt: openArray[byte], ikm: openArray[byte], info: openArray[byte] ) : GenericArray =
func hkdfExtract*(key: openArray[byte], seed: openArray[byte]) : GenericArray =

assert GenericArray.len == sha256.digestSize()

var ctx{.noInit.}: HKDF[sha256]
var prk{.noInit.}: array[sha256.digestSize(), byte]
ctx.hkdfExtract(prk, salt, ikm)
ctx.hkdfExtract(prk, key, seed)

return prk

Expand Down