extracting mpi from a S-exp crypted with RSA

Moritz Schulte mo at g10code.com
Wed Apr 20 16:22:41 CEST 2005


On Tue, Apr 19, 2005 at 07:00:14PM +0000, flebool wrote:

Hello,

>  the crypted S-exp CRYPTED is represented as:
> 
>           (enc-val
>             (rsa
>               (a A-MPI)))

Correct.

> Calling the function:
> int legth=gcrypt_sexp_length(CRYPTED);
> I get length=2.

Correct, you have two objects in that S-Expression:

 1. "enc-val"
 2. (rsa (a A-MPI))

> i want to get the mpi (a A-MPI),(that i've understood to be the crypted text 
> in MPI format) but the function
> 
> gcry_mpi_t internal_mpi = gcry_sexp_nth_mpi(CRYPTED,1,GCRYMPI_FMT_USG);
> 
> fails.

You need to distringuish between the S-Expression containing the MPI
and it's label `(a A-MPI)' and the actual MPI value, which is `A-MPI'.

So, before you can use gcry_sexp_nth_mpi(), you need to extract the
sub-S-Expression, i.e.:

a = (enc-val (rsa (a A-MPI)));
b = sexp_nth (a, 1); // extract `(rsa (a A-MPI))'
mpi = sexp_mpi (b, 1; // extract `A-MPI'.

Alternatively, you can also use gcry_sexp_find_token().

> for completeness,i post the output of a 
> writt= gcry_sexp_sprint ( CRYPTED , GCRYSEXP_FMT_DEFAULT , buf_test2 ,(size_t) 
> 500);

By the way: GCRYSEXP_FMT_ADVANCED is much more appropriate for output
intended to be human-readable.

Thanks,
Moritz

-- 
Moritz Schulte
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 193 bytes
Desc: not available
Url : /pipermail/attachments/20050420/b1ab0212/attachment-0001.pgp


More information about the Gcrypt-devel mailing list