diff --git a/chronosim/rijndael.nim b/chronosim/rijndael.nim new file mode 100644 index 0000000..3fe190c --- /dev/null +++ b/chronosim/rijndael.nim @@ -0,0 +1,82 @@ +# +# +# NimCrypto +# (c) Copyright 2023 Status +# +# See the file "LICENSE", included in this +# distribution, for details about the copyright. +# + +## This module implements a no-op(NOP) crypto that does nothing. +## It exports it as AES for emulation purposes, where encryption +## is just extra CPU load, but not needed. +## Do not use for anything else than testing !!! + +{.deadCodeElim:on.} + +when sizeof(int) == 4: + type + NopContext[bits: static[uint]] = object + skey: array[120, uint32] + nr: int +elif sizeof(int) == 8: + type + NopContext[bits: static[uint]] = object + skey: array[120, uint64] + nr: int + +type + nop128* = NopContext[128] + nop192* = NopContext[192] + nop256* = NopContext[256] + nop* = nop128 | nop192 | nop256 + +proc encrypt*(ctx: NopContext, input: openarray[byte], + output: var openarray[byte]) = + for i, v in input: + output[i] = v + +proc decrypt*(ctx: NopContext, input: openarray[byte], + output: var openarray[byte]) = + for i, v in input: + output[i] = v + +template sizeKey*(ctx: NopContext): int = + (ctx.bits div 8) + +template sizeBlock*(ctx: NopContext): int = + (16) + +template sizeKey*(r: typedesc[nop]): int = + when r is nop128: + (16) + elif r is nop192: + (24) + elif r is nop256: + (32) + +template sizeBlock*(r: typedesc[nop]): int = + (16) + +proc init*(ctx: var NopContext, key: openarray[byte]) {.inline.} = + discard + +proc init*(ctx: var NopContext, key: ptr byte, nkey: int = 0) {.inline.} = + discard + +proc clear*(ctx: var NopContext) {.inline.} = + discard + +proc encrypt*(ctx: var NopContext, inbytes: ptr byte, + outbytes: ptr byte) {.inline.} = + outbytes = inbytes + +proc decrypt*(ctx: var NopContext, inbytes: ptr byte, + outbytes: ptr byte) {.inline.} = + outbytes = inbytes + +# export as AES to replace it with NOP +type + aes128* = nop128 + aes192* = nop192 + aes256* = nop256 diff --git a/das.nims b/das.nims index 5e159f9..b240795 100644 --- a/das.nims +++ b/das.nims @@ -1 +1,2 @@ patchFile("chronos", "chronos", "chronosim/chronos") +patchFile("nimcrypto", "rijndael", "chronosim/rijndael") diff --git a/vendor/nim-libp2p-dht b/vendor/nim-libp2p-dht index 8b3d676..43f8a6d 160000 --- a/vendor/nim-libp2p-dht +++ b/vendor/nim-libp2p-dht @@ -1 +1 @@ -Subproject commit 8b3d67688069784a5651a18f672e0b2ada74e3b7 +Subproject commit 43f8a6d1824780a1d99dc642a6dac2153d958b21