fix up extra/crypto
parent
426ec8a08b
commit
b35db385d3
|
@ -1,4 +1,7 @@
|
||||||
|
! Copyright (C) 2008 DoDoug Coleman.
|
||||||
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: crypto.barrett kernel math namespaces tools.test ;
|
USING: crypto.barrett kernel math namespaces tools.test ;
|
||||||
|
IN: crypto.barrett.tests
|
||||||
|
|
||||||
[ HEX: 1f63edfb7e838622c7412eafaf0439cf0cdf3aae8bdd09e2de69b509a53883a83560d5ce50ea039e4 ] [ HEX: 827c67f31b2b46afa49ed95d7f7a3011e5875f7052d4c55437ce726d3c6ce0dc9c445fda63b6dc4e 16 barrett-mu ] unit-test
|
[ HEX: 1f63edfb7e838622c7412eafaf0439cf0cdf3aae8bdd09e2de69b509a53883a83560d5ce50ea039e4 ] [ HEX: 827c67f31b2b46afa49ed95d7f7a3011e5875f7052d4c55437ce726d3c6ce0dc9c445fda63b6dc4e 16 barrett-mu ] unit-test
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,12 @@
|
||||||
|
! Copyright (C) 2008 Doug Coleman.
|
||||||
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: kernel math math.functions ;
|
USING: kernel math math.functions ;
|
||||||
IN: crypto.barrett
|
IN: crypto.barrett
|
||||||
|
|
||||||
: barrett-mu ( n size -- mu )
|
: barrett-mu ( n size -- mu )
|
||||||
#! Calculates Barrett's reduction parameter mu
|
#! Calculates Barrett's reduction parameter mu
|
||||||
#! size = word size in bits (8, 16, 32, 64, ...)
|
#! 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 ;
|
||||||
[ log2 1+ ] [ / 2 * ] bi*
|
|
||||||
] [
|
|
||||||
2^ rot ^ swap /i
|
|
||||||
] 2bi ;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
Doug Coleman
|
|
|
@ -1,17 +0,0 @@
|
||||||
USING: arrays kernel io io.binary sbufs splitting grouping
|
|
||||||
strings sequences namespaces math math.parser parser
|
|
||||||
hints math.bitwise assocs ;
|
|
||||||
IN: crypto.common
|
|
||||||
|
|
||||||
: (nth-int) ( string n -- int )
|
|
||||||
2 shift dup 4 + rot <slice> ; inline
|
|
||||||
|
|
||||||
: nth-int ( string n -- int ) (nth-int) le> ; inline
|
|
||||||
|
|
||||||
: update ( num var -- ) [ w+ ] change ; inline
|
|
||||||
|
|
||||||
SYMBOL: big-endian?
|
|
||||||
|
|
||||||
: mod-nth ( n seq -- elt )
|
|
||||||
#! 5 "abcd" -> b
|
|
||||||
[ length mod ] [ nth ] bi ;
|
|
|
@ -1,4 +1,4 @@
|
||||||
USING: arrays combinators crypto.common checksums checksums.md5
|
USING: arrays combinators checksums checksums.md5
|
||||||
checksums.sha1 checksums.md5.private io io.binary io.files
|
checksums.sha1 checksums.md5.private io io.binary io.files
|
||||||
io.streams.byte-array kernel math math.vectors memoize sequences
|
io.streams.byte-array kernel math math.vectors memoize sequences
|
||||||
io.encodings.binary ;
|
io.encodings.binary ;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
USING: kernel math namespaces crypto.rsa tools.test ;
|
USING: kernel math namespaces crypto.rsa tools.test ;
|
||||||
|
IN: crypto.rsa.tests
|
||||||
|
|
||||||
[ 123456789 ] [ 128 generate-rsa-keypair 123456789 over rsa-encrypt swap rsa-decrypt ] unit-test
|
[ 123456789 ] [ 128 generate-rsa-keypair 123456789 over rsa-encrypt swap rsa-decrypt ] unit-test
|
||||||
[ 123456789 ] [ 129 generate-rsa-keypair 123456789 over rsa-encrypt swap rsa-decrypt ] unit-test
|
[ 123456789 ] [ 129 generate-rsa-keypair 123456789 over rsa-encrypt swap rsa-decrypt ] unit-test
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
! Copyright (C) 2008 Doug Coleman.
|
||||||
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: math.miller-rabin kernel math math.functions namespaces
|
USING: math.miller-rabin kernel math math.functions namespaces
|
||||||
sequences accessors ;
|
sequences accessors ;
|
||||||
IN: crypto.rsa
|
IN: crypto.rsa
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Cryptographic algorithms implemented in Factor, such as MD5 and SHA1
|
HMAC, XOR, Barrett, RSA, Timing
|
||||||
|
|
|
@ -2,23 +2,24 @@ USING: continuations crypto.xor kernel strings tools.test ;
|
||||||
IN: crypto.xor.tests
|
IN: crypto.xor.tests
|
||||||
|
|
||||||
! No key
|
! No key
|
||||||
[ "" dup xor-crypt ] [ T{ no-xor-key f } = ] must-fail-with
|
[ "" dup xor-crypt ] [ T{ empty-xor-key } = ] must-fail-with
|
||||||
[ { } dup xor-crypt ] [ T{ no-xor-key f } = ] must-fail-with
|
[ { } dup xor-crypt ] [ T{ empty-xor-key } = ] must-fail-with
|
||||||
[ V{ } dup xor-crypt ] [ T{ no-xor-key f } = ] must-fail-with
|
[ V{ } dup xor-crypt ] [ T{ empty-xor-key } = ] must-fail-with
|
||||||
[ "" "asdf" dupd xor-crypt xor-crypt ] [ T{ no-xor-key f } = ] must-fail-with
|
[ "" "asdf" dupd xor-crypt xor-crypt ] [ T{ empty-xor-key } = ] must-fail-with
|
||||||
|
|
||||||
! a xor a = 0
|
! a xor a = 0
|
||||||
[ "\0\0\0\0\0\0\0" ] [ "abcdefg" dup xor-crypt ] unit-test
|
[ "\0\0\0\0\0\0\0" ] [ "abcdefg" dup xor-crypt ] unit-test
|
||||||
|
|
||||||
[ { 15 15 15 15 } ] [ { 10 10 10 10 } { 5 5 5 5 } xor-crypt ] unit-test
|
[ { 15 15 15 15 } ] [ { 10 10 10 10 } { 5 5 5 5 } xor-crypt ] unit-test
|
||||||
|
|
||||||
[ "asdf" ] [ "key" "asdf" dupd xor-crypt xor-crypt >string ] unit-test
|
[ "asdf" ] [ "asdf" "key" [ xor-crypt ] [ xor-crypt ] bi >string ] unit-test
|
||||||
[ "" ] [ "key" "" xor-crypt >string ] unit-test
|
[ "" ] [ "" "key" xor-crypt >string ] unit-test
|
||||||
[ "a longer message...!" ] [
|
[ "a longer message...!" ] [
|
||||||
"."
|
"a longer message...!"
|
||||||
"a longer message...!" dupd xor-crypt xor-crypt >string
|
"." [ xor-crypt ] [ xor-crypt ] bi >string
|
||||||
] unit-test
|
] unit-test
|
||||||
[ "a longer message...!" ] [
|
[ "a longer message...!" ] [
|
||||||
|
"a longer message...!"
|
||||||
"a very long key, longer than the message even."
|
"a very long key, longer than the message even."
|
||||||
"a longer message...!" dupd xor-crypt xor-crypt >string
|
[ xor-crypt ] [ xor-crypt ] bi >string
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
USING: crypto.common kernel math sequences ;
|
! Copyright (C) 2008 Doug Coleman.
|
||||||
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
|
USING: kernel math sequences fry ;
|
||||||
IN: crypto.xor
|
IN: crypto.xor
|
||||||
|
|
||||||
ERROR: no-xor-key ;
|
: mod-nth ( n seq -- elt ) [ length mod ] [ nth ] bi ;
|
||||||
|
|
||||||
: xor-crypt ( key seq -- seq' )
|
ERROR: empty-xor-key ;
|
||||||
over empty? [ no-xor-key ] when
|
|
||||||
dup length rot [ mod-nth bitxor ] curry 2map ;
|
: xor-crypt ( seq key -- seq' )
|
||||||
|
dup empty? [ empty-xor-key ] when
|
||||||
|
[ dup length ] dip '[ _ mod-nth bitxor ] 2map ;
|
||||||
|
|
Loading…
Reference in New Issue