Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
pike
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pikelang
pike
Commits
7fcd54e4
Commit
7fcd54e4
authored
27 years ago
by
Niels Möller
Browse files
Options
Downloads
Patches
Plain Diff
Remember the primes associated with a private key (not used, except by the
pkcs module). Rev: lib/modules/Crypto/rsa.pike:1.12
parent
b0c9f74e
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/modules/Crypto/rsa.pike
+38
-15
38 additions, 15 deletions
lib/modules/Crypto/rsa.pike
with
38 additions
and
15 deletions
lib/modules/Crypto/rsa.pike
+
38
−
15
View file @
7fcd54e4
/* $Id: rsa.pike,v 1.1
1
1997/1
0/12 14:39:47 grubba
Exp $
/* $Id: rsa.pike,v 1.1
2
1997/1
1/28 10:04:31 nisse
Exp $
*
*
* Follow the PKCS#1 standard for padding and encryption.
* Follow the PKCS#1 standard for padding and encryption.
* However, PKCS#1 style signing (involving ISO Object Identifiers) is
* not yet implemented.
*/
*/
#define bignum object(Gmp.mpz)
#define bignum object(Gmp.mpz)
...
@@ -13,6 +11,11 @@ bignum e; /* public exponent */
...
@@ -13,6 +11,11 @@ bignum e; /* public exponent */
bignum d; /* private exponent (if known) */
bignum d; /* private exponent (if known) */
int size;
int size;
/* Extra info associated with a private key. Not currently used. */
bignum p;
bignum q;
int encrypt_mode; /* For block cipher compatible functions */
int encrypt_mode; /* For block cipher compatible functions */
object set_public_key(bignum modulo, bignum pub)
object set_public_key(bignum modulo, bignum pub)
...
@@ -26,9 +29,14 @@ object set_public_key(bignum modulo, bignum pub)
...
@@ -26,9 +29,14 @@ object set_public_key(bignum modulo, bignum pub)
return this_object();
return this_object();
}
}
object set_private_key(bignum priv)
object set_private_key(bignum priv
, array(bignum)|void extra
)
{
{
d = priv;
d = priv;
if (extra)
{
p = extra[0];
q = extra[1];
}
return this_object();
return this_object();
}
}
...
@@ -55,6 +63,12 @@ bignum rsa_pad(string message, int type, mixed|void random)
...
@@ -55,6 +63,12 @@ bignum rsa_pad(string message, int type, mixed|void random)
throw( ({ "Crypto.rsa->rsa_pad: Too large block.\n",
throw( ({ "Crypto.rsa->rsa_pad: Too large block.\n",
backtrace() }) );
backtrace() }) );
switch(type)
{
case 1:
cookie = sprintf("%@c", replace(allocate(len), 0, 0xff));
break;
case 2:
if (random)
if (random)
cookie = replace(random(len), "\0", "\1");
cookie = replace(random(len), "\0", "\1");
else
else
...
@@ -62,7 +76,11 @@ bignum rsa_pad(string message, int type, mixed|void random)
...
@@ -62,7 +76,11 @@ bignum rsa_pad(string message, int type, mixed|void random)
{
{
return random(255) + 1;
return random(255) + 1;
} ));
} ));
break;
default:
throw( ({ "Crypto.rsa->rsa_pad: Unknown type.\n",
backtrace() }) );
}
return BIGNUM(sprintf("%c", type) + cookie + "\0" + message, 256);
return BIGNUM(sprintf("%c", type) + cookie + "\0" + message, 256);
}
}
...
@@ -83,8 +101,13 @@ object sign(string message, program h, mixed|void r)
...
@@ -83,8 +101,13 @@ object sign(string message, program h, mixed|void r)
int verify(string msg, program h, object sign)
int verify(string msg, program h, object sign)
{
{
// werror(sprintf("msg: '%s'\n", Crypto.string_to_hex(msg)));
string s = pkcs.build_digestinfo(msg, h());
string s = pkcs.build_digestinfo(msg, h());
return s == rsa_unpad(sign->powm(e, n), 1);
// werror(sprintf("rsa: s = '%s'\n", s));
// werror(sprintf("decrypted: '%s'\n", sign->powm(e, n)->digits(256)));
string s2 = rsa_unpad(sign->powm(e, n), 1);
// werror(sprintf("rsa: s2 = '%s'\n", s2));
return s == s2;
}
}
string sha_sign(string message, mixed|void r)
string sha_sign(string message, mixed|void r)
...
@@ -123,8 +146,8 @@ object generate_key(int bits, function|void r)
...
@@ -123,8 +146,8 @@ object generate_key(int bits, function|void r)
do
do
{
{
bignum
p = get_prime(bits, r);
p = get_prime(bits, r);
bignum
q = get_prime(bits, r);
q = get_prime(bits, r);
bignum phi = Gmp.mpz(p-1)*Gmp.mpz(q-1);
bignum phi = Gmp.mpz(p-1)*Gmp.mpz(q-1);
array gs; /* gcd(pub, phi), and pub^-1 mod phi */
array gs; /* gcd(pub, phi), and pub^-1 mod phi */
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment