summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>1999-10-09 18:37:01 +0000
committerWerner Koch <wk@gnupg.org>1999-10-09 18:37:01 +0000
commitfb525a0f45066df7bd088d70b4fb24798e8b7583 (patch)
tree19916a9fc40a4f360868a8327bbdf53b705b02e6
parentac8cc5ece8c2b62fc491ecc2a2383a2d49ce4bce (diff)
downloadlibgcrypt-STABLE-BRANCH-1-0.tar.gz
See ChangeLog: Sat Oct 9 20:34:41 CEST 1999 Werner KochSTABLE-BRANCH-1-0
-rw-r--r--src/README3
-rw-r--r--src/mdapi.c128
-rw-r--r--src/mpiapi.c346
-rw-r--r--src/pkapi.c67
-rw-r--r--src/symapi.c151
5 files changed, 0 insertions, 695 deletions
diff --git a/src/README b/src/README
deleted file mode 100644
index 74396541..00000000
--- a/src/README
+++ /dev/null
@@ -1,3 +0,0 @@
-This directory will contain sources for libgcrypt.
-Because it is still under development, no source
-is provided and compilation is disabled.
diff --git a/src/mdapi.c b/src/mdapi.c
deleted file mode 100644
index a0bbc648..00000000
--- a/src/mdapi.c
+++ /dev/null
@@ -1,128 +0,0 @@
-/* mdapi.c - message digest function interface
- * Copyright (C) 1998 Free Software Foundation, Inc.
- *
- * This file is part of GnuPG.
- *
- * GnuPG is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * GnuPG is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- */
-
-#include <config.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
-#include <assert.h>
-
-#define GCRYPT_NO_MPI_MACROS 1
-#include "g10lib.h"
-#include "cipher.h"
-#include "memory.h"
-
-
-int
-gcry_md_open( GCRY_MD_HD *ret_hd, int algo, unsigned flags )
-{
- GCRY_MD_HD hd;
-
- /* fixme: check that algo is available and that only valid
- * flag values are used */
- hd = md_open( algo, (flags & GCRY_MD_FLAG_SECURE) );
- *ret_hd = hd;
- return 0;
-}
-
-void
-gcry_md_close( GCRY_MD_HD hd )
-{
- md_close( hd );
-}
-
-int
-gcry_md_enable( GCRY_MD_HD hd, int algo )
-{
- /* fixme: check that algo is available */
- md_enable( hd, algo );
- return 0;
-}
-
-GCRY_MD_HD
-gcry_md_copy( GCRY_MD_HD hd )
-{
- return md_copy( hd );
-}
-
-int
-gcry_md_ctl( GCRY_MD_HD hd, int cmd, byte *buffer, size_t buflen)
-{
- if( cmd == GCRYCTL_FINALIZE )
- md_final( hd );
- else if( cmd == GCRYCTL_FINALIZE )
- md_final( hd );
- else
- return GCRYERR_INV_OP;
- return 0;
-}
-
-void
-gcry_md_write( GCRY_MD_HD hd, const byte *inbuf, size_t inlen)
-{
- md_write( hd, (byte*)inbuf, inlen );
-}
-
-/****************
- * Read out the complete digest, this function implictly finalizes
- * the hash.
- */
-byte *
-gcry_md_read( GCRY_MD_HD hd, int algo )
-{
- gcry_md_ctl( hd, GCRYCTL_FINALIZE, NULL, 0 );
- return md_read( hd, algo);
-}
-
-int
-gcry_md_algo( GCRY_MD_HD hd )
-{
- return md_get_algo( hd );
-}
-
-/****************
- * Return the length of the digest in bytes.
- */
-size_t
-gcry_md_dlen( int algo )
-{
- /* we do some very quick checks here */
- switch( algo )
- {
- case GCRY_MD_MD5: return 16;
- case GCRY_MD_SHA1:
- case GCRY_MD_RMD160: return 20;
- default: return 0; /* fixme: pass it to a lookup function */
- }
-}
-
-
-/****************
- * Read out an intermediate digest.
- */
-int
-gcry_md_get( GCRY_MD_HD hd, int algo, byte *buffer, int buflen )
-{
- return GCRYERR_INTERNAL;
-}
-
-
-
diff --git a/src/mpiapi.c b/src/mpiapi.c
deleted file mode 100644
index 28841652..00000000
--- a/src/mpiapi.c
+++ /dev/null
@@ -1,346 +0,0 @@
-/* mpiapi.a - MPI function interface
- * Copyright (C) 1998 Free Software Foundation, Inc.
- *
- * This file is part of GnuPG.
- *
- * GnuPG is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * GnuPG is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- */
-
-#include <config.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
-#include <assert.h>
-
-#define GCRYPT_NO_MPI_MACROS 1
-#include "g10lib.h"
-#include "mpi.h"
-#include "../cipher/random.h"
-
-
-GCRY_MPI
-gcry_mpi_new( unsigned int nbits )
-{
- return mpi_alloc( (nbits+BITS_PER_MPI_LIMB-1) / BITS_PER_MPI_LIMB );
-}
-
-
-GCRY_MPI
-gcry_mpi_snew( unsigned int nbits )
-{
- return mpi_alloc_secure( (nbits+BITS_PER_MPI_LIMB-1) / BITS_PER_MPI_LIMB );
-}
-
-void
-gcry_mpi_release( GCRY_MPI a )
-{
- mpi_free( a );
-}
-
-GCRY_MPI
-gcry_mpi_copy( const GCRY_MPI a )
-{
- return mpi_copy( (GCRY_MPI)a );
-}
-
-GCRY_MPI
-gcry_mpi_set( GCRY_MPI w, const GCRY_MPI u )
-{
- if( !w )
- w = mpi_alloc( mpi_get_nlimbs(u) );
- mpi_set( w, (GCRY_MPI)u );
- return w;
-}
-
-GCRY_MPI
-gcry_mpi_set_ui( GCRY_MPI w, unsigned long u )
-{
- if( !w )
- w = mpi_alloc(1);
- mpi_set_ui( w, u );
- return w;
-}
-
-
-int
-gcry_mpi_cmp( const GCRY_MPI u, const GCRY_MPI v )
-{
- return mpi_cmp( (GCRY_MPI)u, (GCRY_MPI)v );
-}
-
-int
-gcry_mpi_cmp_ui( const GCRY_MPI u, unsigned long v )
-{
- return mpi_cmp_ui( (GCRY_MPI)u, v );
-}
-
-
-void
-gcry_mpi_randomize( GCRY_MPI w,
- unsigned int nbits, enum gcry_random_level level )
-{
- char *p = get_random_bits( nbits, level, mpi_is_secure(w) );
- mpi_set_buffer( w, p, (nbits+7)/8, 0 );
- m_free(p);
-}
-
-
-
-int
-gcry_mpi_scan( struct gcry_mpi **ret_mpi, enum gcry_mpi_format format,
- const char *buffer, size_t *nbytes )
-{
- struct gcry_mpi *a = NULL;
- unsigned int len;
-
- len = nbytes? *nbytes : strlen(buffer);
-
- /* TODO: add a way to allocate the MPI in secure memory
- * Hmmm: maybe it is better to retrieve this information from
- * the provided buffer. */
- if( format == GCRYMPI_FMT_STD ) {
- const byte *s = buffer;
-
- a = mpi_alloc( (len+BYTES_PER_MPI_LIMB-1) / BYTES_PER_MPI_LIMB );
- if( len ) { /* not zero */
- a->sign = *s & 0x80;
- if( a->sign ) {
- /* FIXME: we have to convert from 2compl to magnitude format */
- mpi_free(a);
- return GCRYERR_INTERNAL;
- }
- else
- mpi_set_buffer( a, s, len, 0 );
- }
- if( ret_mpi )
- *ret_mpi = a;
- else
- mpi_free(a);
- return 0;
- }
- else if( format == GCRYMPI_FMT_USG ) {
- a = mpi_alloc( (len+BYTES_PER_MPI_LIMB-1) / BYTES_PER_MPI_LIMB );
- if( len ) /* not zero */
- mpi_set_buffer( a, buffer, len, 0 );
- if( ret_mpi )
- *ret_mpi = a;
- else
- mpi_free(a);
- return 0;
- }
- else if( format == GCRYMPI_FMT_PGP ) {
- a = mpi_read_from_buffer( (char*)buffer, &len, 0 );
- if( nbytes )
- *nbytes = len;
- if( ret_mpi )
- *ret_mpi = a;
- else
- mpi_free(a);
- return a? 0 : GCRYERR_INV_OBJ;
- }
- else if( format == GCRYMPI_FMT_SSH ) {
- const byte *s = buffer;
- size_t n;
-
- if( len < 4 )
- return GCRYERR_TOO_SHORT;
- n = s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3];
- s += 4; len -= 4;
- if( n > len )
- return GCRYERR_TOO_LARGE; /* or should it be too_short */
-
- a = mpi_alloc( (n+BYTES_PER_MPI_LIMB-1) / BYTES_PER_MPI_LIMB );
- if( len ) { /* not zero */
- a->sign = *s & 0x80;
- if( a->sign ) {
- /* FIXME: we have to convert from 2compl to magnitude format */
- mpi_free(a);
- return GCRYERR_INTERNAL;
- }
- else
- mpi_set_buffer( a, s, n, 0 );
- }
- if( nbytes )
- *nbytes = n+4;
- if( ret_mpi )
- *ret_mpi = a;
- else
- mpi_free(a);
- return 0;
- }
- else if( format == GCRYMPI_FMT_HEX ) {
- if( nbytes )
- return GCRYERR_INV_ARG; /* can only handle C strings for now */
- a = mpi_alloc(0);
- if( mpi_fromstr( a, buffer ) )
- return GCRYERR_INV_OBJ;
- if( ret_mpi )
- *ret_mpi = a;
- else
- mpi_free(a);
- return 0;
- }
- else
- return GCRYERR_INV_ARG;
-}
-
-/****************
- * Write a in format into buffer which has a length of *NBYTES.
- * Return the number of bytes actually written in nbytes.
- * TODO: Move this stuff to mpicoder.c or replace mpicoder.c
- */
-int
-gcry_mpi_print( enum gcry_mpi_format format, char *buffer, size_t *nbytes,
- struct gcry_mpi *a )
-{
- unsigned int nbits = mpi_get_nbits(a);
- size_t len;
-
- if( !nbytes )
- return GCRYERR_INV_ARG;
-
- len = *nbytes;
- if( format == GCRYMPI_FMT_STD ) {
- byte *s = buffer;
- char *tmp;
- int extra = 0;
- unsigned int n;
-
- if( a->sign )
- return GCRYERR_INTERNAL; /* can't handle it yet */
-
- tmp = mpi_get_buffer( a, &n, NULL );
- if( n && (*tmp & 0x80) ) {
- n++;
- extra=1;
- }
-
- if( n > len ) {
- m_free(tmp);
- return GCRYERR_TOO_SHORT; /* the provided buffer is too short */
- }
- if( extra )
- *s++ = 0;
-
- 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 )
- 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);
- *nbytes = n+2;
- return 0;
- }
- else if( format == GCRYMPI_FMT_SSH ) {
- byte *s = buffer;
- char *tmp;
- int extra = 0;
- unsigned int n;
-
- if( a->sign )
- return GCRYERR_INTERNAL; /* can't handle it yet */
-
- tmp = mpi_get_buffer( a, &n, NULL );
- if( n && (*tmp & 0x80) ) {
- n++;
- extra=1;
- }
-
- if( n+4 > len ) {
- 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 );
- m_free(tmp);
- *nbytes = 4+n;
- return 0;
- }
- else if( format == GCRYMPI_FMT_HEX ) {
- byte *s = buffer;
- byte *tmp;
- int i;
- int extra = 0;
- unsigned int n=0;
-
- tmp = mpi_get_buffer( a, &n, NULL );
- if( !n || (*tmp & 0x80) )
- extra=1;
-
- if( 2*n+3+1 > len ) {
- m_free(tmp);
- return GCRYERR_TOO_SHORT; /* the provided buffer is too short */
- }
- if( a->sign )
- *s++ = '-';
- if( extra ) {
- *s++ = '0';
- *s++ = '0';
- }
-
- #if BYTES_PER_MPI_LIMB == 2
- #define X "4"
- #elif BYTES_PER_MPI_LIMB == 4
- #define X "8"
- #elif BYTES_PER_MPI_LIMB == 8
- #define X "16"
- #else
- #error please define the format here
- #endif
- 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;
- #undef X
- return 0;
- }
- else
- return GCRYERR_INV_ARG;
-}
-
-
-void
-gcry_mpi_powm( MPI w, MPI b, MPI e, MPI m )
-{
- mpi_powm( w, b, e, m );
-}
-
-
diff --git a/src/pkapi.c b/src/pkapi.c
deleted file mode 100644
index 7d48c4c9..00000000
--- a/src/pkapi.c
+++ /dev/null
@@ -1,67 +0,0 @@
-/* pkapi.c - public key function interface
- * Copyright (C) 1998 Free Software Foundation, Inc.
- *
- * This file is part of GnuPG.
- *
- * GnuPG is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * GnuPG is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- */
-
-#include <config.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
-#include <assert.h>
-
-#include "g10lib.h"
-
-
-
-
-
-
-int
-gcry_pk_encrypt( GCRY_SEXP *result, GCRY_SEXP data, GCRY_SEXP pkey )
-{
- /* ... */
- return 0;
-}
-
-int
-gcry_pk_decrypt( GCRY_SEXP *result, GCRY_SEXP data, GCRY_SEXP skey )
-{
- /* ... */
- return 0;
-}
-
-int
-gcry_pk_sign( GCRY_SEXP *result, GCRY_SEXP data, GCRY_SEXP skey )
-{
- GCRY_SEXP s;
- /* get the secret key */
- s = gcry_sexp_find_token( skey, "private-key", 0 );
- if( !s )
- return -1; /* no private key */
- /* ... */
- return 0;
-}
-
-int
-gcry_pk_verify( GCRY_SEXP *result, GCRY_SEXP data, GCRY_SEXP pkey )
-{
- /* ... */
- return 0;
-}
-
diff --git a/src/symapi.c b/src/symapi.c
deleted file mode 100644
index e2aca4e2..00000000
--- a/src/symapi.c
+++ /dev/null
@@ -1,151 +0,0 @@
-/* symapi.c - symmetric cipher function interface
- * Copyright (C) 1998 Free Software Foundation, Inc.
- *
- * This file is part of GnuPG.
- *
- * GnuPG is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * GnuPG is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- */
-
-/* fixme: merge this function with ../cipher/cipher.c */
-
-#include <config.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
-#include <assert.h>
-
-#include "g10lib.h"
-#define G10_MPI_H /* fake mpi.h header */
-#include "cipher.h"
-
-/* FIXME: We should really have the m_lib functions to allow
- * overriding of the default malloc functions
- * For now use this kludge: */
-#define m_lib_alloc m_alloc
-#define m_lib_alloc_clear m_alloc_clear
-#define m_lib_free m_free
-
-
-#define CONTEXT_MAGIC 0x12569afe
-
-struct gcry_cipher_context {
- u32 magic;
- int mode;
- unsigned flags;
- CIPHER_HANDLE hd;
-};
-
-
-int
-gcry_cipher_open( GCRY_CIPHER_HD *ret_hd, int algo, int mode, unsigned flags )
-{
- GCRY_CIPHER_HD h;
-
- /* check whether the algo is available */
- if( check_cipher_algo( algo ) )
- return set_lasterr( GCRYERR_INV_ALGO );
-
- /* check flags */
- if( (flags & ~(GCRY_CIPHER_SECURE|GCRY_CIPHER_ENABLE_SYNC)) )
- return set_lasterr( GCRYERR_INV_ARG );
-
- /* map mode to internal mode */
- switch( mode ) {
- case GCRY_CIPHER_MODE_NONE: mode = CIPHER_MODE_DUMMY; break;
- case GCRY_CIPHER_MODE_ECB: mode = CIPHER_MODE_ECB; break;
- case GCRY_CIPHER_MODE_CFB:
- mode = (flags & GCRY_CIPHER_ENABLE_SYNC) ? CIPHER_MODE_PHILS_CFB
- : CIPHER_MODE_CFB;
- break;
- case GCRY_CIPHER_MODE_CBC: mode = CIPHER_MODE_CBC; break;
- default:
- return set_lasterr( GCRYERR_INV_ALGO );
- }
-
- /* FIXME: issue a warning when CIPHER_MODE_NONE is used */
-
- /* allocate the handle */
- h = m_lib_alloc_clear( sizeof *h );
- if( !h )
- return set_lasterr( GCRYERR_NOMEM );
- h->magic = CONTEXT_MAGIC;
- h->mode = mode;
- h->hd = cipher_open( algo, mode, (flags & GCRY_CIPHER_SECURE) );
- if( !h ) {
- m_lib_free( h );
- return set_lasterr( GCRYERR_INTERNAL );
- }
-
- *ret_hd = h;
- return 0;
-}
-
-
-void
-gcry_cipher_close( GCRY_CIPHER_HD h )
-{
- if( !h )
- return;
- if( h->magic != CONTEXT_MAGIC ) {
- fatal_invalid_arg("gcry_cipher_close: already closed/invalid handle");
- return;
- }
- cipher_close( h->hd );
- h->magic = 0;
- m_lib_free(h);
-}
-
-int gcry_cipher_ctl( GCRY_CIPHER_HD h, int cmd, byte *buffer, size_t buflen)
-{
- switch( cmd ) {
- case GCRYCTL_SET_KEY:
- cipher_setkey( h->hd, buffer, buflen );
- break;
- case GCRYCTL_SET_IV:
- cipher_setiv( h->hd, buffer, buflen );
- break;
- case GCRYCTL_CFB_SYNC:
- cipher_sync( h->hd );
- default:
- return set_lasterr( GCRYERR_INV_OP );
- }
- return 0;
-}
-
-
-int
-gcry_cipher_encrypt( GCRY_CIPHER_HD h, byte *out, size_t outsize,
- byte *in, size_t inlen )
-{
- if( outsize < inlen )
- return set_lasterr( GCRYERR_TOO_SHORT );
- /* fixme: check that the inlength is a multipe of the blocksize
- * if a blockoriented mode is used, or modify cipher_encrypt to
- * return an error in this case */
- cipher_encrypt( h->hd, out, in, inlen );
- return 0;
-}
-
-int
-gcry_cipher_decrypt( GCRY_CIPHER_HD h, byte *out, size_t outsize,
- byte *in, size_t inlen )
-{
- if( outsize < inlen )
- return set_lasterr( GCRYERR_TOO_SHORT );
- cipher_decrypt( h->hd, out, in, inlen );
- return 0;
-}
-