Module: TTCrypt
- Defined in:
- lib/ttcrypt.rb,
lib/ttcrypt.rb,
lib/ttcrypt/version.rb,
ext/ttcrypt/ttcrypt_ruby.cpp
Defined Under Namespace
Classes: RsaKey
Constant Summary collapse
- VERSION =
'0.1.1'
Class Method Summary collapse
- ._factorize ⇒ Object
- ._factorize2 ⇒ Object
- ._generate_prime ⇒ Object
-
.factorize(composite) ⇒ int
Pollard ‘rho’ prime factorization.
-
.generate_prime(bits) ⇒ Object
Generate random probable prime number with a given bits length.
-
.sha256(source) ⇒ String
Generate fast SHA256 hash of a source string and return it in the binary form.
-
.sha512(source) ⇒ String
Generate fast SHA512 hash of a source string and return it in the binary form.
Class Method Details
._factorize ⇒ Object
._factorize2 ⇒ Object
._generate_prime ⇒ Object
.factorize(composite) ⇒ int
Pollard ‘rho’ prime factorization. Allows execution of other ruby threads in parallel (releases GVL)
47 48 49 50 51 52 |
# File 'lib/ttcrypt.rb', line 47 def factorize composite _factorize2(composite.to_bytes).map { |f| f.bytes_to_integer } # hex = composite.to_i.to_s(16) # hex = '0' + hex if (hex.length & 1) == 1 # _factorize(hex).map { |x| x.to_i(16) } end |
.generate_prime(bits) ⇒ Object
Generate random probable prime number with a given bits length. This implementation will generate prime such as 2^(bits-1) < prime < 2 ^ bits.
57 58 59 |
# File 'lib/ttcrypt.rb', line 57 def generate_prime bits _generate_prime(bits).to_i(16) end |
.sha256(source) ⇒ String
Generate fast SHA256 hash of a source string and return it in the binary form
73 74 75 |
# File 'lib/ttcrypt.rb', line 73 def sha256(source) # stub for documentation, real finction is in the native code end |
.sha512(source) ⇒ String
Generate fast SHA512 hash of a source string and return it in the binary form
65 66 67 |
# File 'lib/ttcrypt.rb', line 65 def sha512(source) # stub for documentation, real finction is in the native code end |