Moved eel and eapml under the contrib folder.
This commit is contained in:
62
contrib/ise_library/text/encryption/eel/RSA/rsa_key_pair.e
Normal file
62
contrib/ise_library/text/encryption/eel/RSA/rsa_key_pair.e
Normal file
@@ -0,0 +1,62 @@
|
||||
note
|
||||
description: "Summary description for {RSA_KEY_PAIR}."
|
||||
author: "Colin LeMahieu"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
quote: "If you think health care is expensive now, wait until you see what it costs when it's free. - P.J. O'Rourke (1993)"
|
||||
|
||||
class
|
||||
RSA_KEY_PAIR
|
||||
|
||||
inherit
|
||||
DEBUG_OUTPUT
|
||||
|
||||
create
|
||||
make,
|
||||
make_with_exponent
|
||||
|
||||
feature {NONE}
|
||||
make (bits: INTEGER)
|
||||
local
|
||||
e: INTEGER_X
|
||||
p: INTEGER_X
|
||||
q: INTEGER_X
|
||||
n: INTEGER_X
|
||||
p_bits: INTEGER
|
||||
do
|
||||
p_bits := (bits + 1) // 2
|
||||
create e.make_from_integer (65537)
|
||||
create p.make_random_prime (p_bits)
|
||||
create q.make_random_prime (bits - p_bits)
|
||||
n := p * q
|
||||
create public.make (n, e)
|
||||
create private.make (p, q, n, e)
|
||||
end
|
||||
|
||||
make_with_exponent (bits: INTEGER e_a: INTEGER_X)
|
||||
require
|
||||
e_a.is_probably_prime
|
||||
local
|
||||
p: INTEGER_X
|
||||
q: INTEGER_X
|
||||
n: INTEGER_X
|
||||
p_bits: INTEGER
|
||||
do
|
||||
p_bits := (bits + 1) // 2
|
||||
create p.make_random_prime (p_bits)
|
||||
create q.make_random_prime (bits - p_bits)
|
||||
n := p * q
|
||||
create public.make (n, e_a)
|
||||
create private.make (p, q, n, e_a)
|
||||
end
|
||||
|
||||
feature
|
||||
public: RSA_PUBLIC_KEY
|
||||
private: RSA_PRIVATE_KEY
|
||||
|
||||
feature {NONE} --{DEBUG_OUTPUT}
|
||||
debug_output: STRING
|
||||
do
|
||||
result := "P: " + private.p.debug_output + " Q: " + private.q.debug_output + " D: " + private.d.debug_output + " N: " + public.modulus.debug_output + " E: " + public.exponent.debug_output
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,46 @@
|
||||
note
|
||||
description: "Summary description for {RSA_PRIVATE_KEY}."
|
||||
author: "Colin LeMahieu"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
quote: "If you have ten thousand regulations, you destroy all respect for the law. - Winston Churchill"
|
||||
|
||||
class
|
||||
RSA_PRIVATE_KEY
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature
|
||||
make (p_a: INTEGER_X q_a: INTEGER_X n_a: INTEGER_X e_a: INTEGER_X)
|
||||
local
|
||||
phi: INTEGER_X
|
||||
do
|
||||
p := p_a
|
||||
q := q_a
|
||||
n := n_a
|
||||
e := e_a
|
||||
phi := (p - p.one) * (q - q.one)
|
||||
d := e.inverse_value (phi)
|
||||
end
|
||||
|
||||
sign (message: INTEGER_X): INTEGER_X
|
||||
do
|
||||
result := decrypt (message)
|
||||
end
|
||||
|
||||
decrypt (cipher: INTEGER_X): INTEGER_X
|
||||
do
|
||||
result := cipher.powm_value (d, n)
|
||||
end
|
||||
|
||||
feature
|
||||
p: INTEGER_X
|
||||
q: INTEGER_X
|
||||
d: INTEGER_X
|
||||
n: INTEGER_X
|
||||
e: INTEGER_X
|
||||
|
||||
invariant
|
||||
p * q ~ n
|
||||
end
|
||||
43
contrib/ise_library/text/encryption/eel/RSA/rsa_public_key.e
Normal file
43
contrib/ise_library/text/encryption/eel/RSA/rsa_public_key.e
Normal file
@@ -0,0 +1,43 @@
|
||||
note
|
||||
description: "Summary description for {RSA_KEY}."
|
||||
author: "Colin LeMahieu"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
quote: "Tyranny is always better organized than freedom. - Charles Peguy"
|
||||
|
||||
class
|
||||
RSA_PUBLIC_KEY
|
||||
|
||||
inherit
|
||||
DEBUG_OUTPUT
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature
|
||||
make (modulus_a: INTEGER_X exponent_a: INTEGER_X)
|
||||
do
|
||||
modulus := modulus_a
|
||||
exponent := exponent_a
|
||||
end
|
||||
|
||||
verify (message: INTEGER_X signature: INTEGER_X): BOOLEAN
|
||||
do
|
||||
result := encrypt (signature) ~ message
|
||||
end
|
||||
|
||||
encrypt (message: INTEGER_X): INTEGER_X
|
||||
do
|
||||
result := message.powm_value (exponent, modulus)
|
||||
end
|
||||
|
||||
feature
|
||||
modulus: INTEGER_X
|
||||
exponent: INTEGER_X
|
||||
|
||||
feature {RSA_KEY_PAIR}--{DEBUG_OUTPUT}
|
||||
debug_output: STRING
|
||||
do
|
||||
result := "Modulus: 0x" + modulus.out_hex
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user