libgcrypt again: error "conflicting use" in gcry_pk_encrypt

Claudia Reuter reuter at do.isst.fraunhofer.de
Fri Aug 5 12:40:07 CEST 2005


at least a managed it.

code:

void EncryptSessionKey(gcry_sexp_t &encSessionKey, unsigned char*
SessionKey, gcry_sexp_t pKey) {

    gcry_mpi_t a;
    gcry_sexp_t sexp;

    size_t KeyLength;
    int rc;

    KeyLength = gcry_md_get_algo_dlen(SelectedHash);

    //TODO: some padding with sessionkey

    rc = gcry_mpi_scan(&a, GCRYMPI_FMT_USG, SessionKey, KeyLength,
&KeyLength);
    if(rc) throw GeneralError("MPI scan failed.\n%s\n", gpg_strerror( rc ));

    rc = gcry_sexp_build(&sexp, NULL, "%m", a);
    if(rc) throw GeneralError("Unable to build S-Expression.\n%s\n",
gpg_strerror( rc ));

    rc = gcry_pk_encrypt(&encSessionKey, sexp, pKey);
    if(rc) {
        gcry_sexp_release(sexp);
        throw GeneralError("Unable to encrypt session key.\n%s\n",
gpg_strerror( rc ));
    }

    return;

}

greetings

Claudia Reuter wrote:

>hi everybody.
>
>so now I try to create a session key to encrypt my text files. this
>seems to work. the session key must of course be encrypted with some
>public key. Now an error "conflicting use" occurs in the gcry_pk_encrypt
>function.
>
>Maybe anyone could tell me what's wrong.
>
>    gcry_md_open( &Hash , SelectedHash , 0 );
>    // Retrive digest size
>    HashDigestSize = gcry_md_get_algo_dlen( SelectedHash );
>
>    Salt = (unsigned int*)gcry_random_bytes( SelectedSaltLength ,
>GCRY_STRONG_RANDOM );
>
>    // Add salt to hash
>    gcry_md_write( Hash , Salt , SelectedSaltLength );
>
>    // Fetch digest
>    HashResult = gcry_md_read( Hash , SelectedHash );
>   
>    //HashResult = (unsigned char*)
>malloc(SelectedSaltLength*sizeof(char));
>    //gcry_randomize(HashResult, SelectedSaltLength, GCRY_STRONG_RANDOM);
>
>    rc = gcry_sexp_build(&sexp, NULL, "(data (flags pkcs1) (hash sha256
>%b))", HashDigestSize, HashResult);
>   
>    if(rc) {
>        throw GeneralError( "Unable to build S-Expression. %s\n" ,
>gpg_strerror( rc ) );
>    }
>
>    rc = gcry_pk_encrypt(&sexpSessionKey, sexp, pKey);
>    if(rc) {
>        throw GeneralError( "Unable to encrypt session key. %s\n",
>gpg_strerror( rc ) );
>    }
>
>Thanks in advance.
>
>_______________________________________________
>Gnupg-users mailing list
>Gnupg-users at gnupg.org
>http://lists.gnupg.org/mailman/listinfo/gnupg-users
>  
>



More information about the Gnupg-users mailing list