Oh my, this is what I get for not reading the Factor mailing list.
I've done my own independent implementation of crypto.aes:
https://github.com/phred/factor/tree/implement-aes
It's based on the original, which used 7zip's infuriatingly optimized C
implementation as a reference. It uses 32-bit integer arithmetic and lookup
tables for encrypt and decrypt.
Reading through the smart commentary in this thread, I've already found some
cleanup to do. I'd also like to benchmark my code.
All of this may turn out to be just an academic exercise on my part. ;-)
I actually find Gabriel's "pure" implementation much more aesthetically
pleasing than my own. Lookup tables muddy the code's readability, and feel
more like "hey, I'm shoehorning C into Factor" than an elegant expression of
the core AES algorithms. Adding OpenSSL bindings also limits the utility of a
"pure Factor" optimized lookup-table implementation (unless we can get close to
OpenSSL's numbers, that'd be wicked!)
So pleased to see that the community's chugging along! It will be nice to have
a working crypto.aes implementation in the core. I don't wish to compete for
submission to the project, nor step on anyone's toes.
Some notes on my implementation:
---
I used HOOKs to implement a generic AES "crypt" algorithm, which to me seems
concise and elegant:
: (aes-crypt) ( aes -- aes' )
(first-round) [
dup nrounds>> (counter)
[ [ (do-round) ] dip add-round-key drop ] with each
] keep
(final-round) ;
aes-encrypt and aes-decrypt "strategies" provide their own implementations of
the (first-round), (final-round), etc. words.
I tried to use the '-unsafe' sequence words, inline, and unrolled-map wherever
I could in the implementation. This was more of a sprinkling of "hey, that'd
be good" rather than driven by hard benchmark numbers.
Your feedback is most welcome. Thanks!
--
Fred Alger
@_phred
------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:
Build for Windows Store.
http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk