factor/extra/crypto/barrett/barrett.factor

15 lines
339 B
Factor

USING: kernel math math.functions ;
IN: crypto.barrett
: barrett-mu ( n size -- mu )
#! Calculates Barrett's reduction parameter mu
#! size = word size in bits (8, 16, 32, 64, ...)
! over log2 1+ over / 2 * >r 2 swap ^ r> ^ swap / floor ;
[
[ log2 1+ ] [ / 2 * ] bi*
] [
2^ rot ^ swap /i
] 2bi ;