-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Some blowfish modes don't work #34
Comments
A workaround is to edit the library to make import nimcrypto
import strutils
proc encryptData*(key: string, data: string, iv: string): string =
var ctx: CBC[blowfish]
result = newString(len(data))
ctx.cipher.init(key.toOpenArrayByte(0, key.len-1))
copyMem(addr ctx.iv[0], unsafeAddr iv[0], ctx.sizeBlock)
ctx.encrypt(data.toOpenArrayByte(0, data.len - 1), result.toOpenArrayByte(0, result.len - 1))
proc decryptData*(key: string, data: string, iv: string): string =
var ctx: CBC[blowfish]
result = newString(len(data))
ctx.cipher.init(key.toOpenArrayByte(0, key.len-1))
copyMem(addr ctx.iv[0], unsafeAddr iv[0], ctx.sizeBlock)
ctx.decrypt(data.toOpenArrayByte(0, data.len - 1), result.toOpenArrayByte(0, result.len - 1))
var encryptedData = encryptData("abc", "this is a test", "12345678")
var decryptedData = decryptData("abc", encryptedData, "12345678")
echo encryptedData.toHex()
echo decryptedData So, to make this compile you would change the CBC*[T] = object
cipher*: T
iv*: array[MaxBlockBytesSize, byte]
# ... This also works for other types like CFB. |
Sorry, but currently Blowfish modes are not supported, mostly because of Nim's generic bugs and limitations and because Blowfish do not has fixed key size. I need some time to find proper solution to fix it, but currently i dont have enough free time. |
@MatthewScholefield : thanks again for your reply on gmail, i had some "python to nim" work to be done before trying your workaround. But as you noticed results are different for CBC mode between python's and nim's test. |
edited |
I'm closing this issue, because this is not right place for advertising of your own projects. @hed0n1st @MatthewScholefield this issue could be reopened if author will remove ads from this issue. |
@cheatfate The author edited their post to remove the link. But come on, the dude just posted a link to his solution to a task that doesn't even work with your library. Let's all be friendly here. No need to get touchy about someone sharing a project that solves a current issue with a library. |
I'm not sure if there's something I'm doing improperly, but I tried instantiating a
CBC[blowfish]
context and.init()
doesn't seem to work:Here's the build output:
This seems to result from the following function in
bcmode.nim
:However, I have no idea why it can't see the
cipher
field (even when I try changing it to be a public member ofCBC
).Any idea why it errors or if I'm initializing it improperly?
The text was updated successfully, but these errors were encountered: