diff options
author | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2001-06-16 22:41:17 +0000 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2001-06-16 22:41:17 +0000 |
commit | b915dd6188f03da709a9f0be6684e0b5d137bdc2 (patch) | |
tree | af014be8b3aa51492c831485e16cd9ddacb2580d /lib | |
parent | 549279f8d2f32acd54699cccbf1e3ace9e0da515 (diff) | |
download | gnutls-b915dd6188f03da709a9f0be6684e0b5d137bdc2.tar.gz |
some support for public key encryption (rsa)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gnutls_pk.c | 77 | ||||
-rw-r--r-- | lib/gnutls_pk.h | 2 |
2 files changed, 79 insertions, 0 deletions
diff --git a/lib/gnutls_pk.c b/lib/gnutls_pk.c new file mode 100644 index 0000000000..716139890b --- /dev/null +++ b/lib/gnutls_pk.c @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2001 Nikos Mavroyanopoulos + * + * This file is part of GNUTLS. + * + * GNUTLS 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. + * + * GNUTLS 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 <defines.h> +#include <gnutls_int.h> +#include <gnutls_gcry.h> +#include <gnutls_pk.h> +#include <gnutls_errors.h> + +/* this is taken from gnupg + */ + +/**************** + * Emulate our old PK interface here - sometime in the future we might + * change the internal design to directly fit to libgcrypt. + */ +int _gnutls_pk_encrypt(enum gcry_pk_algos algo, MPI * resarr, MPI data, MPI * pkey) +{ + GCRY_SEXP s_ciph, s_data, s_pkey; + int rc; + + /* make a sexp from pkey */ + if (algo == GCRY_PK_RSA) { + rc = gcry_sexp_build(&s_pkey, NULL, + "(public-key(rsa(p%m)(e%m)))", + pkey[0], pkey[1] ); + } else { + gnutls_assert(); + return GNUTLS_E_UNKNOWN_KX_ALGORITHM; + } + + if (rc!=0) { + gnutls_assert(); + return GNUTLS_E_UNKNOWN_ERROR; + } + + /* put the data into a simple list */ + if (gcry_sexp_build(&s_data, NULL, "%m", data)) { + gnutls_assert(); + return GNUTLS_E_UNKNOWN_ERROR; + } + + /* pass it to libgcrypt */ + rc = gcry_pk_encrypt(&s_ciph, s_data, s_pkey); + gcry_sexp_release(s_data); + gcry_sexp_release(s_pkey); + + if (rc); + else { /* add better error handling or make gnupg use S-Exp directly */ + GCRY_SEXP list = gcry_sexp_find_token(s_ciph, "a", 0); + /* assert(list); */ + resarr[0] = gcry_sexp_nth_mpi(list, 1, 0); + /* assert(resarr[0]); */ + gcry_sexp_release(list); + + } + + gcry_sexp_release(s_ciph); + return rc; +} diff --git a/lib/gnutls_pk.h b/lib/gnutls_pk.h new file mode 100644 index 0000000000..bcb0c5243a --- /dev/null +++ b/lib/gnutls_pk.h @@ -0,0 +1,2 @@ +int _gnutls_pk_encrypt(enum gcry_pk_algos algo, MPI * resarr, MPI data, MPI * pkey); + |