summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cipher/primegen.c3
-rw-r--r--cipher/pubkey.c24
-rw-r--r--mpi/ChangeLog8
-rw-r--r--mpi/mpicoder.c125
-rw-r--r--src/gcrypt.h1
-rw-r--r--src/mpi.h1
6 files changed, 93 insertions, 69 deletions
diff --git a/cipher/primegen.c b/cipher/primegen.c
index 1ad16333..45033790 100644
--- a/cipher/primegen.c
+++ b/cipher/primegen.c
@@ -241,7 +241,8 @@ generate_elg_prime( int mode, unsigned pbits, unsigned qbits,
mpi_add_ui(g, g, 1);
if( DBG_CIPHER ) {
log_debug("checking g: ");
- mpi_print( stderr, g, 1 );
+ /*mpi_print( stderr, g, 1 );*/
+ #warning we need an internal mpi_print for debugging
}
else
progress('^');
diff --git a/cipher/pubkey.c b/cipher/pubkey.c
index 4b2c55e4..86b797df 100644
--- a/cipher/pubkey.c
+++ b/cipher/pubkey.c
@@ -635,6 +635,17 @@ release_mpi_array( MPI *array )
*
* Returns: A pointer to an allocated array of MPIs if the return value is
* zero; the caller has to release this array.
+ *
+ * Example of a DSA public key:
+ * (private-key
+ * (dsa
+ * (p <mpi>)
+ * (g <mpi>)
+ * (y <mpi>)
+ * (x <mpi>)
+ * )
+ * )
+ * The <mpi> are expected to be in GCRYMPI_FMT_USG
*/
static int
sexp_to_key( GCRY_SEXP sexp, int want_private, MPI **retarray, int *retalgo)
@@ -783,8 +794,8 @@ gcry_pk_decrypt( GCRY_SEXP *result, GCRY_SEXP data, GCRY_SEXP skey )
/****************
* Create a signature.
*
- * Caller has to provide a secret kez as the SEXP skey and data expressed
- * as a SEXP list hash with only one emelennt which should instantly be
+ * Caller has to provide a secret key as the SEXP skey and data expressed
+ * as a SEXP list hash with only one element which should instantly be
* available as a MPI. Later versions of this functions may provide padding
* and other things depending on data.
*
@@ -793,6 +804,15 @@ gcry_pk_decrypt( GCRY_SEXP *result, GCRY_SEXP data, GCRY_SEXP skey )
* signature value; the structure of this signature depends on the
* other arguments but is always suitable to be passed to
* gcry_pk_verify
+ *
+ * s_hash = (<mpi>)
+ * s_skey = <key-as-defined-in-sexp_to_key>
+ * r_sig = (sig-val
+ * (<algo>
+ * (<param_name1> <mpi>)
+ * ...
+ * (<param_namen> <mpi>)
+ * ))
*/
int
gcry_pk_sign( GCRY_SEXP *r_sig, GCRY_SEXP s_hash, GCRY_SEXP s_skey )
diff --git a/mpi/ChangeLog b/mpi/ChangeLog
index 81fec2a0..2a85de0e 100644
--- a/mpi/ChangeLog
+++ b/mpi/ChangeLog
@@ -1,3 +1,11 @@
+Fri Dec 31 12:48:31 CET 1999 Werner Koch <wk@gnupg.de>
+
+ * mpicoder.c (mpi_read_from_buffer): Made static.
+ (gcry_mpi_print): A buffer of NULL is now allowed to get the required
+ length back.
+ (mpi_get_keyid): Removed.
+ (mpi_print): Made static - should be removed.
+
Wed Dec 8 21:58:32 CET 1999 Werner Koch <wk@gnupg.de>
* Makefile.am (INCLUDES): Add ../gcrypt.
diff --git a/mpi/mpicoder.c b/mpi/mpicoder.c
index 352468cb..753c1767 100644
--- a/mpi/mpicoder.c
+++ b/mpi/mpicoder.c
@@ -32,7 +32,7 @@
#define MAX_EXTERN_MPI_BITS 16384
-MPI
+static MPI
mpi_read_from_buffer(byte *buffer, unsigned *ret_nread, int secure)
{
int i, j;
@@ -156,7 +156,7 @@ mpi_fromstr(MPI val, const char *str)
* printed.
* FIXME: Replace this by the more generic gcry_mpi_print()
*/
-int
+static int
mpi_print( FILE *fp, MPI a, int mode )
{
int i, n=0;
@@ -202,30 +202,6 @@ g10_log_mpidump( const char *text, MPI a )
fputc('\n', fp);
}
-/****************
- * Special function to get the low 8 bytes from an mpi.
- * This can be used as a keyid; KEYID is an 2 element array.
- * Return the low 4 bytes.
- */
-u32
-mpi_get_keyid( MPI a, u32 *keyid )
-{
-#if BYTES_PER_MPI_LIMB == 4
- if( keyid ) {
- keyid[0] = a->nlimbs >= 2? a->d[1] : 0;
- keyid[1] = a->nlimbs >= 1? a->d[0] : 0;
- }
- return a->nlimbs >= 1? a->d[0] : 0;
-#elif BYTES_PER_MPI_LIMB == 8
- if( keyid ) {
- keyid[0] = a->nlimbs? (u32)(a->d[0] >> 32) : 0;
- keyid[1] = a->nlimbs? (u32)(a->d[0] & 0xffffffff) : 0;
- }
- return a->nlimbs? (u32)(a->d[0] & 0xffffffff) : 0;
-#else
- #error Make this function work with other LIMB sizes
-#endif
-}
/****************
@@ -453,6 +429,7 @@ gcry_mpi_scan( struct gcry_mpi **ret_mpi, enum gcry_mpi_format format,
/****************
* Write a using format into buffer which has a length of *NBYTES.
* Returns the number of bytes actually written in nbytes.
+ * Buffer maybe NULL to query the required length of the buffer
*/
int
gcry_mpi_print( enum gcry_mpi_format format, char *buffer, size_t *nbytes,
@@ -465,8 +442,8 @@ gcry_mpi_print( enum gcry_mpi_format format, char *buffer, size_t *nbytes,
return GCRYERR_INV_ARG;
len = *nbytes;
+ *nbytes = 0;
if( format == GCRYMPI_FMT_STD ) {
- byte *s = buffer;
char *tmp;
int extra = 0;
unsigned int n;
@@ -480,39 +457,43 @@ gcry_mpi_print( enum gcry_mpi_format format, char *buffer, size_t *nbytes,
extra=1;
}
- if( n > len ) {
+ if( n > len && buffer ) {
m_free(tmp);
return GCRYERR_TOO_SHORT; /* the provided buffer is too short */
}
- if( extra )
- *s++ = 0;
+ if( buffer ) {
+ byte *s = buffer;
+ if( extra )
+ *s++ = 0;
- memcpy( s, tmp, n-extra );
+ memcpy( s, tmp, n-extra );
+ }
m_free(tmp);
*nbytes = n;
return 0;
}
else if( format == GCRYMPI_FMT_PGP ) {
unsigned int n = (nbits + 7)/8;
- byte *s = buffer;
- char *tmp;
if( a->sign )
return GCRYERR_INV_ARG; /* pgp format can only handle unsigned */
- if( n+2 > len )
+ if( n+2 > len && buffer )
return GCRYERR_TOO_SHORT; /* the provided buffer is too short */
- s[0] = nbits >> 8;
- s[1] = nbits;
-
- tmp = mpi_get_buffer( a, &n, NULL );
- memcpy( s+2, tmp, n );
- m_free(tmp);
+ if( buffer ) {
+ char *tmp;
+ byte *s = buffer;
+ s[0] = nbits >> 8;
+ s[1] = nbits;
+
+ tmp = mpi_get_buffer( a, &n, NULL );
+ memcpy( s+2, tmp, n );
+ m_free(tmp);
+ }
*nbytes = n+2;
return 0;
}
else if( format == GCRYMPI_FMT_SSH ) {
- byte *s = buffer;
char *tmp;
int extra = 0;
unsigned int n;
@@ -526,24 +507,26 @@ gcry_mpi_print( enum gcry_mpi_format format, char *buffer, size_t *nbytes,
extra=1;
}
- if( n+4 > len ) {
+ if( n+4 > len && buffer ) {
m_free(tmp);
return GCRYERR_TOO_SHORT; /* the provided buffer is too short */
}
- *s++ = n >> 24;
- *s++ = n >> 16;
- *s++ = n >> 8;
- *s++ = n;
- if( extra )
- *s++ = 0;
-
- memcpy( s, tmp, n-extra );
+ if( buffer ) {
+ byte *s = buffer;
+ *s++ = n >> 24;
+ *s++ = n >> 16;
+ *s++ = n >> 8;
+ *s++ = n;
+ if( extra )
+ *s++ = 0;
+
+ memcpy( s, tmp, n-extra );
+ }
m_free(tmp);
*nbytes = 4+n;
return 0;
}
else if( format == GCRYMPI_FMT_HEX ) {
- byte *s = buffer;
byte *tmp;
int i;
int extra = 0;
@@ -553,25 +536,37 @@ gcry_mpi_print( enum gcry_mpi_format format, char *buffer, size_t *nbytes,
if( !n || (*tmp & 0x80) )
extra=1;
- if( 2*n+3+1 > len ) {
+ if( 2*n+3+1 > len && buffer ) {
m_free(tmp);
return GCRYERR_TOO_SHORT; /* the provided buffer is too short */
}
- if( a->sign )
- *s++ = '-';
- if( extra ) {
- *s++ = '0';
- *s++ = '0';
- }
+ if( buffer ) {
+ byte *s = buffer;
+ if( a->sign )
+ *s++ = '-';
+ if( extra ) {
+ *s++ = '0';
+ *s++ = '0';
+ }
- for(i=0; i < n; i++ ) {
- unsigned int c = tmp[i];
- *s++ = (c >> 4) < 10? '0'+(c>>4) : 'A'+(c>>4)-10 ;
- c &= 15;
- *s++ = c < 10? '0'+c : 'A'+c-10 ;
+ for(i=0; i < n; i++ ) {
+ unsigned int c = tmp[i];
+ *s++ = (c >> 4) < 10? '0'+(c>>4) : 'A'+(c>>4)-10 ;
+ c &= 15;
+ *s++ = c < 10? '0'+c : 'A'+c-10 ;
+ }
+ *s++ = 0;
+ *nbytes = (char*)s - buffer;
+ }
+ else {
+ *nbytes = n;
+ if( a->sign )
+ ++*nbytes;
+ if( extra )
+ *nbytes += 2;
+ ++*nbytes; /* terminating Nul */
}
- *s++ = 0;
- *nbytes = (char*)s - buffer;
+ m_free(tmp);
return 0;
}
else
diff --git a/src/gcrypt.h b/src/gcrypt.h
index aea01190..46119181 100644
--- a/src/gcrypt.h
+++ b/src/gcrypt.h
@@ -218,6 +218,7 @@ void *gcry_mpi_get_opaque( GCRY_MPI a, unsigned int *nbits );
void gcry_mpi_set_flag( GCRY_MPI a, enum gcry_mpi_flag flag );
void gcry_mpi_clear_flag( GCRY_MPI a, enum gcry_mpi_flag flag );
int gcry_mpi_get_flag( GCRY_MPI a, enum gcry_mpi_flag flag );
+unsigned int gcry_mpi_get_nbits( GCRY_MPI a );
#ifndef GCRYPT_NO_MPI_MACROS
diff --git a/src/mpi.h b/src/mpi.h
index f92a1f8b..a55b44fb 100644
--- a/src/mpi.h
+++ b/src/mpi.h
@@ -95,7 +95,6 @@ void mpi_m_check( MPI a );
void mpi_swap( MPI a, MPI b);
/*-- mpicoder.c --*/
-MPI mpi_read_from_buffer(byte *buffer, unsigned *ret_nread, int secure);
int mpi_fromstr(MPI val, const char *str);
int mpi_print( FILE *fp, MPI a, int mode );
void g10_log_mpidump( const char *text, MPI a );