factor/extra/crypto/barrett/barrett.factor

11 lines
346 B
Factor
Raw Normal View History

2008-10-02 19:45:51 -04:00
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
2007-09-20 18:09:08 -04:00
USING: kernel math math.functions ;
IN: crypto.barrett
: barrett-mu ( n size -- mu )
2015-09-08 19:15:10 -04:00
! Calculates Barrett's reduction parameter mu
! size = word size in bits (8, 16, 32, 64, ...)
[ [ log2 1 + ] [ / 2 * ] bi* ]
2008-10-02 19:45:51 -04:00
[ 2^ rot ^ swap /i ] 2bi ;