Warning: stream of thought/opinion.  I'm pretty prone to bikeshedding.

1) The first thing I noticed was the code representing words as 4-byte
arrays, which initially made me see red---red ink, that is, from all my
memories of getting stuck grading college students' AES implementations.
:-) But I see you're aware of it.  It's probably a nice "next step" to
take.  This is also the first I've seen of Factor's math.bits /
math.bitwise vocabs.  Very nice, indeed.  Might consider another virtual
sequence for words, then the implementations might not have to change.
Although, I'm not sure if a virtual sequence could even translate rot-word
(i.e., `cut-slice prepend`) into a simple rotational bitwise shift...

2) `sbox` could be defined as a `CONSTANT:`.
http://docs.factorcode.org/content/article-words.constant.html

3) You could use the `literals` vocab for `rcon` to make it a constant,
too: `CONSTANT: rcon $[ 0x01 11 make-xtime ]`.  Might run into parse-time
problems, I suppose, in which case `MEMO:` is perfectly suitable.  I see
`t-table` and `d-table` are defined as such, which is probably what you
were following.  http://docs.factorcode.org/content/article-literals.html

4) Whenver you use `sbox` or `inv-sbox`, you immediately have to call
`nth`.  It might be nice to have words like `: sub-byte ( b -- b' ) sbox
nth ; inline`.

5) Am I missing something, or is `xtime` using 0x1b where it should be
using 0x11b?

6) I would call `nxtime` something like `mult` or `gf-mult`, since it's
multiplication in GF(2^8) modulo m(x) = x^8 + x^4 + x^3 + x + 1.  And I'd
probably use a more meaningful stack effect declaration, like ( a(x) b(x)
-- a(x)*b(x) ) or even ( a(x) b(x) -- a(x)*b(x)%m(x) ).  Then, I think
`nxtime` is a better name for what `make-xtime` is currently doing (calling
`xtime` `n` times).  Maybe `nxtimes`, so it reads like "n `xtimes`s".

7) It's technically OK, but uncommon to see stack effects like you have on
`xor-word`.  ( word word -- word ) reads like "takes two of the same value,
outputs an unchanged value".  If you were to use locals, it wouldn't even
work out correctly:

  IN: scratchpad :: foo ( a a -- a ) a a + ;
  IN: scratchpad 100 2 foo .
  4

You could go with a lengthy stack effect like ( word1 word2 -- word1^word2
), or at least give the values distinct names like ( a b -- c ), though
that's clearly a worse declaration because a, b, and c are meaningless.

Similarly, you'd more commonly see stack effects like ( state -- state' )
rather than the ( state -- state ) you have on various words.

8) It'd be spiffy to wrap all this implementation into some `encrypt` and
`decrypt` words that would crank through a sequence/stream of bytes and
encrypt/decrypt block-wise.  So that, for example, you could
encrypt/decrypt an entire file.  But then, this gets into block cipher
modes, so I'm sure there are subtleties to iron out there...I'm no
cryptographer.

All in all, good work!  I'm impressed by how short & simple all the word
definitions are, coming from grading Java implementations.

Nice job,
--Alex Vondrak



On Mon, May 27, 2013 at 10:39 AM, John Benediktsson <mrj...@gmail.com>wrote:

> Two general approaches, where both run the garbage collector before timing
> or profiling:
>
> 1) basic timing information;
>
>     gc [ foo ] time
>
>     (or if the word is slow, run it a few times)
>
>     gc [ 1,000 [ foo ] times ] time
>
> 2) profiling
>
>    gc [ foo ] profile
>
>    This saves the profile, allowing you to view it various ways:
>
>    top-down profile.
>    top-down-max-depth profile.
>    flat profile.
>
>    Etc
>
>
>
> On May 27, 2013, at 10:19 AM, Gabriel Kerneis <gabr...@kerneis.info>
> wrote:
>
> > On Mon, May 27, 2013 at 09:51:04AM -0700, John Benediktsson wrote:
> >> Nice!  Have you had a chance to look at performance?
> >
> > Not yet, but this is on my TODO list.  I'm working on ECB and CBC modes,
> so it's
> > probably worth finishing that first and then test with large files.
> >
> > Is there any recommanded way to benchmark execution time (or performance
> in
> > general) in Factor?
> >
> > Best regards,
> > --
> > Gabriel
> >
> >
> ------------------------------------------------------------------------------
> > Try New Relic Now & We'll Send You this Cool Shirt
> > New Relic is the only SaaS-based application performance monitoring
> service
> > that delivers powerful full stack analytics. Optimize and monitor your
> > browser, app, & servers with just a few lines of code. Try New Relic
> > and get this awesome Nerd Life shirt!
> http://p.sf.net/sfu/newrelic_d2d_may
> > _______________________________________________
> > Factor-talk mailing list
> > Factor-talk@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/factor-talk
>
>
> ------------------------------------------------------------------------------
> Try New Relic Now & We'll Send You this Cool Shirt
> New Relic is the only SaaS-based application performance monitoring service
> that delivers powerful full stack analytics. Optimize and monitor your
> browser, app, & servers with just a few lines of code. Try New Relic
> and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_may
> _______________________________________________
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
------------------------------------------------------------------------------
Try New Relic Now & We'll Send You this Cool Shirt
New Relic is the only SaaS-based application performance monitoring service 
that delivers powerful full stack analytics. Optimize and monitor your
browser, app, & servers with just a few lines of code. Try New Relic
and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_may
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to