moving the NOP cipher to this repo

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
Csaba Kiraly 2023-06-15 11:55:48 +02:00
parent c9d20230bf
commit 6eb3af41d2
No known key found for this signature in database
GPG Key ID: 0FE274EE8C95166E
3 changed files with 84 additions and 1 deletions

82
chronosim/rijndael.nim Normal file
View File

@ -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

View File

@ -1 +1,2 @@
patchFile("chronos", "chronos", "chronosim/chronos")
patchFile("nimcrypto", "rijndael", "chronosim/rijndael")

@ -1 +1 @@
Subproject commit 8b3d67688069784a5651a18f672e0b2ada74e3b7
Subproject commit 43f8a6d1824780a1d99dc642a6dac2153d958b21