Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Dmitry Baryshkov
nettle
Commits
0c57a71a
Commit
0c57a71a
authored
Oct 01, 2002
by
Niels Möller
Browse files
* examples/rsa-keygen.c: Use functions from io.c.
* examples/rsa-sign.c: Likewise. Rev: src/nettle/examples/rsa-sign.c:1.2
parent
129d8042
Changes
1
Hide whitespace changes
Inline
Side-by-side
examples/rsa-sign.c
View file @
0c57a71a
...
@@ -26,7 +26,7 @@
...
@@ -26,7 +26,7 @@
# include "config.h"
# include "config.h"
#endif
/* HAVE_CONFIG_H */
#endif
/* HAVE_CONFIG_H */
#if !
HAVE_LIBGMP
#if !
WITH_PUBLIC_KEY
int
int
main
(
int
argc
,
char
**
argv
)
main
(
int
argc
,
char
**
argv
)
{
{
...
@@ -35,54 +35,15 @@ main(int argc, char **argv)
...
@@ -35,54 +35,15 @@ main(int argc, char **argv)
"and recompile Nettle
\n
"
);
"and recompile Nettle
\n
"
);
return
EXIT_FAILURE
;
return
EXIT_FAILURE
;
}
}
#e
ndif
/* !HAVE_LIBGMP
*/
#e
lse
/* WITH_PUBLIC_KEY
*/
#include <errno.h>
#include <errno.h>
#include <stdlib.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include "rsa.h"
#include "rsa.h"
#include "io.h"
#define BUFSIZE 1000
static
int
read_key
(
const
char
*
name
,
struct
rsa_private_key
*
key
)
{
uint8_t
buffer
[
BUFSIZE
];
unsigned
done
;
int
fd
=
open
(
name
,
O_RDONLY
);
if
(
fd
<
0
)
{
fprintf
(
stderr
,
"Failed to open `%s': %s
\n
"
,
name
,
strerror
(
errno
));
return
0
;
}
for
(
done
=
0
;
done
<
sizeof
(
buffer
)
;)
{
int
res
=
read
(
fd
,
buffer
,
sizeof
(
buffer
)
-
done
);
if
(
!
res
)
break
;
else
if
(
res
<
0
&&
errno
==
EINTR
)
continue
;
else
if
(
res
<
0
)
{
fprintf
(
stderr
,
"Failed reading `%s': %s
\n
"
,
name
,
strerror
(
errno
));
return
0
;
}
else
done
+=
res
;
}
return
rsa_keypair_from_sexp
(
NULL
,
key
,
done
,
buffer
);
}
int
int
main
(
int
argc
,
char
**
argv
)
main
(
int
argc
,
char
**
argv
)
...
@@ -99,30 +60,18 @@ main(int argc, char **argv)
...
@@ -99,30 +60,18 @@ main(int argc, char **argv)
rsa_init_private_key
(
&
key
);
rsa_init_private_key
(
&
key
);
if
(
!
read_key
(
argv
[
1
],
&
key
))
if
(
!
read_
rsa_
key
(
argv
[
1
],
NULL
,
&
key
))
{
{
fprintf
(
stderr
,
"Invalid key
\n
"
);
fprintf
(
stderr
,
"Invalid key
\n
"
);
return
EXIT_FAILURE
;
return
EXIT_FAILURE
;
}
}
sha1_init
(
&
hash
);
sha1_init
(
&
hash
);
for
(;;
)
if
(
!
hash_file
(
&
nettle_sha1
,
&
hash
,
stdin
)
)
{
{
uint8_t
buffer
[
BUFSIZE
];
fprintf
(
stderr
,
"Failed reading stdin: %s
\n
"
,
int
res
=
read
(
STDIN_FILENO
,
buffer
,
sizeof
(
buffer
));
strerror
(
errno
));
if
(
!
res
)
return
0
;
/* EOF */
break
;
else
if
(
res
<
0
&&
errno
==
EINTR
)
continue
;
else
if
(
res
<
0
)
{
fprintf
(
stderr
,
"Failed reading stdin: %s
\n
"
,
strerror
(
errno
));
return
0
;
}
else
sha1_update
(
&
hash
,
res
,
buffer
);
}
}
mpz_init
(
s
);
mpz_init
(
s
);
...
@@ -142,3 +91,4 @@ main(int argc, char **argv)
...
@@ -142,3 +91,4 @@ main(int argc, char **argv)
return
EXIT_SUCCESS
;
return
EXIT_SUCCESS
;
}
}
#endif
/* WITH_PUBLIC_KEY */
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment