This module implements Blowfish crypto algorithm by Bruce Schneier
Code based on C implementation of the Blowfish algorithm created by Paul Kocher [https://www.schneier.com/code/bfsh-koc.zip].
Tests made according to official test vectors by Eric Young [https://www.schneier.com/code/vectors.txt] and adopted version by Randy L. Milbert [https://www.schneier.com/code/vectors2.txt], except chaining mode tests.
Implementation was made with "blowfish bug" in mind [https://www.schneier.com/blowfish-bug.txt]
Some warnings from Paul Kocher:
Warning #1: The code does not check key lengths. (Caveat encryptor.) Warning #2: Beware that Blowfish keys repeat such that "ab" = "abab". Warning #3: It is normally a good idea to zeroize the BLOWFISH_CTX before freeing it. Warning #4: Endianness conversions are the responsibility of the caller. (To encrypt bytes on a little-endian platforms, you'll probably want to swap bytes around instead of just casting.) Warning #5: Make sure to use a reasonable mode of operation for your application. (If you don't know what CBC mode is, see Warning #7.) Warning #6: This code is susceptible to timing attacks. Warning #7: Security engineering is risky and non-intuitive. Have someone check your work. If you don't know what you are doing, get help.
Procs
proc blowfishEncrypt(ctx: var BlowfishContext; inp: ptr byte; oup: ptr byte)
proc blowfishDecrypt(ctx: var BlowfishContext; inp: ptr byte; oup: ptr byte)
- "is greater" operator. This is the same as y < x.
proc initBlowfishContext(ctx: var BlowfishContext; key: ptr byte; nkey: int)
- "is greater or equals" operator. This is the same as y <= x.
proc init(ctx: var BlowfishContext; key: ptr byte; nkey: int) {...}{.inline.}
proc init(ctx: var BlowfishContext; key: openArray[byte]) {...}{.inline.}
- "is greater" operator. This is the same as y < x.
proc clear(ctx: var BlowfishContext) {...}{.inline.}
proc encrypt(ctx: var BlowfishContext; inbytes: ptr byte; outbytes: ptr byte) {...}{.inline.}
proc decrypt(ctx: var BlowfishContext; inbytes: ptr byte; outbytes: ptr byte) {...}{.inline.}
proc encrypt(ctx: var BlowfishContext; input: openArray[byte]; output: var openArray[byte]) {...}{.inline.}
proc decrypt(ctx: var BlowfishContext; input: openArray[byte]; output: var openArray[byte]) {...}{.inline.}