Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
L
lsh
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LSH
lsh
Commits
d26a3a4f
Commit
d26a3a4f
authored
26 years ago
by
Niels Möller
Browse files
Options
Downloads
Patches
Plain Diff
Bug fixes. Seems to work now.
Rev: src/lsh_keygen.c:1.2
parent
3f71e1b9
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/lsh_keygen.c
+39
-25
39 additions, 25 deletions
src/lsh_keygen.c
with
39 additions
and
25 deletions
src/lsh_keygen.c
+
39
−
25
View file @
d26a3a4f
/* lsh_keygen.c
/* lsh_keygen.c
*
*
* Generate dss key pairs..
* Generic key-generation program. Writes a spki-packages private key
* on stdout. You would usually pipe this to some other program to
* extract the public key, encrypt the private key, and save the
* results in two separate files.
*
*
* $Id$
* $Id$ */
*/
/* lsh, an implementation of the ssh protocol
/* lsh, an implementation of the ssh protocol
*
*
...
@@ -26,15 +28,20 @@
...
@@ -26,15 +28,20 @@
#include
"dss_keygen.h"
#include
"dss_keygen.h"
#include
"blocking_write.h"
#include
"crypto.h"
#include
"crypto.h"
#include
"format.h"
#include
"format.h"
#include
"publickey_crypto.h"
#include
"publickey_crypto.h"
#include
"randomness.h"
#include
"randomness.h"
#include
"sexp.h"
#include
"werror.h"
#include
"getopt.h"
#include
"getopt.h"
#include
<stdio.h>
#include
<stdio.h>
#include
<unistd.h>
static
void
usage
(
void
)
NORETURN
;
static
void
usage
(
void
)
NORETURN
;
static
void
usage
(
void
)
static
void
usage
(
void
)
...
@@ -72,52 +79,59 @@ int main(int argc, char **argv)
...
@@ -72,52 +79,59 @@ int main(int argc, char **argv)
r
=
make_poor_random
(
&
sha_algorithm
,
NULL
);
r
=
make_poor_random
(
&
sha_algorithm
,
NULL
);
dss_nist_gen
(
public
.
p
,
public
.
q
,
r
,
l
);
dss_nist_gen
(
public
.
p
,
public
.
q
,
r
,
l
);
mpz_out_str
(
stderr
,
16
,
public
.
p
);
debug_mpz
(
public
.
p
);
printf
(
"
\n
"
);
debug
(
"
\n
"
);
mpz_out_str
(
stderr
,
16
,
public
.
q
);
debug_mpz
(
public
.
q
);
printf
(
"
\n
"
);
debug
(
"
\n
"
);
/* Sanity check. */
/* Sanity check. */
if
(
!
mpz_probab_prime_p
(
q
,
10
))
if
(
!
mpz_probab_prime_p
(
public
.
p
,
10
))
{
{
fprintf
(
stderr
,
"p not a prime!
\n
"
);
werror
(
"p not a prime!
\n
"
);
return
1
;
return
1
;
}
}
if
(
!
mpz_probab_prime_p
(
q
,
10
))
if
(
!
mpz_probab_prime_p
(
public
.
q
,
10
))
{
{
fprintf
(
stderr
,
"p
not a prime!
\n
"
);
werror
(
"q
not a prime!
\n
"
);
return
1
;
return
1
;
}
}
mpz_fdiv_r
(
t
,
p
,
q
);
mpz_fdiv_r
(
t
,
p
ublic
.
p
,
public
.
q
);
if
(
mpz_cmp_ui
(
t
,
1
))
if
(
mpz_cmp_ui
(
t
,
1
))
{
{
fprintf
(
stderr
,
"q doesn't divide p-1 !
\n
"
);
werror
(
"q doesn't divide p-1 !
\n
"
);
return
1
;
return
1
;
}
}
dss_find_generator
(
public
.
g
,
r
,
public
.
p
,
public
.
q
);
dss_find_generator
(
public
.
g
,
r
,
public
.
p
,
public
.
q
);
r
=
make_reasonably_random
();
r
=
make_reasonably_random
();
mpz_set
(
t
,
q
);
mpz_set
(
t
,
public
.
q
);
mpz_sub_ui
(
t
,
t
,
2
);
mpz_sub_ui
(
t
,
t
,
2
);
bignum_random
(
x
,
r
,
t
);
bignum_random
(
x
,
r
,
t
);
mpz_add_ui
(
x
,
x
,
1
);
mpz_add_ui
(
x
,
x
,
1
);
mpz_powm
(
public
.
y
,
public
.
g
,
x
,
public
.
p
);
{
/* Now, output a private key spki structure. */
/* Now, output a private key spki structure. */
struct
sexp
*
key
=
struct
abstract_write
*
output
=
make_blocking_write
(
STDOUT_FILENO
);
sexp_l
(
2
,
sexp_z
(
"private-key"
),
sexp_l
(
6
,
sexp_z
(
"dss"
)
struct
lsh_string
*
key
=
sexp_format
(
sexp_l
(
2
,
sexp_z
(
"private-key"
),
sexp_l
(
6
,
sexp_z
(
"dss"
),
sexp_l
(
2
,
sexp_z
(
"p"
),
sexp_n
(
public
.
p
),
-
1
),
sexp_l
(
2
,
sexp_z
(
"p"
),
sexp_n
(
public
.
p
),
-
1
),
sexp_l
(
2
,
sexp_z
(
"q"
),
sexp_n
(
public
.
q
),
-
1
),
sexp_l
(
2
,
sexp_z
(
"q"
),
sexp_n
(
public
.
q
),
-
1
),
sexp_l
(
2
,
sexp_z
(
"g"
),
sexp_n
(
public
.
g
),
-
1
),
sexp_l
(
2
,
sexp_z
(
"g"
),
sexp_n
(
public
.
g
),
-
1
),
sexp_l
(
2
,
sexp_z
(
"y"
),
sexp_n
(
public
.
y
),
-
1
),
sexp_l
(
2
,
sexp_z
(
"y"
),
sexp_n
(
public
.
y
),
-
1
),
sexp_l
(
2
,
sexp_z
(
"
p
"
),
sexp_n
(
x
),
-
1
),
-
1
),
-
2
);
sexp_l
(
2
,
sexp_z
(
"
x
"
),
sexp_n
(
x
),
-
1
),
-
1
),
-
1
),
SEXP_CANONICAL
);
return
0
;
return
LSH_FAILUREP
(
A_WRITE
(
output
,
key
))
?
1
:
0
;
}
}
}
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