Ticket #6099: libkcapi.patch

File libkcapi.patch, 2.2 KB (added by fijam, 6 years ago)

PoC libkcapi patch

  • libtransmission/crypto-utils-openssl.c

    Patch in libkcapi support (makefile, crypto-utils-openssl.c)
    a b  
    2121#include <openssl/rand.h>
    2222#include <openssl/opensslv.h>
    2323
     24#include <kcapi.h>
     25
    2426#include "transmission.h"
    2527#include "crypto-utils.h"
    2628#include "log.h"
     
    98100tr_sha1_ctx_t
    99101tr_sha1_init (void)
    100102{
    101   EVP_MD_CTX * handle = EVP_MD_CTX_create ();
     103  struct kcapi_handle *handle;
    102104
    103   if (check_result (EVP_DigestInit_ex (handle, EVP_sha1 (), NULL)))
    104     return handle;
     105  handle  = malloc(sizeof(struct kcapi_handle));
     106  if (handle == NULL)
     107    return NULL;
     108  if (kcapi_md_init(handle, "sha1", 0) != 0) {
     109    free(handle);
     110    return NULL;
     111  }
    105112
    106   EVP_MD_CTX_destroy (handle);
    107   return NULL;
     113  return handle;
    108114}
    109115
    110116bool
     
    119125
    120126  assert (data != NULL);
    121127
    122   return check_result (EVP_DigestUpdate (handle, data, data_length));
     128 return (kcapi_md_update((struct kcapi_handle*) handle, data, data_length) == 0);
    123129}
    124130
    125131bool
    126132tr_sha1_final (tr_sha1_ctx_t   handle,
    127133               uint8_t       * hash)
    128134{
    129   bool ret = true;
     135unsigned int hash_length;
    130136
    131137  if (hash != NULL)
    132138    {
    133       unsigned int hash_length;
    134 
    135139      assert (handle != NULL);
    136 
    137       ret = check_result (EVP_DigestFinal_ex (handle, hash, &hash_length));
    138 
    139       assert (!ret || hash_length == SHA_DIGEST_LENGTH);
     140      hash_length = kcapi_md_final (handle, hash, SHA_DIGEST_LENGTH);
     141      assert (hash_length < 0 || hash_length == SHA_DIGEST_LENGTH);
    140142    }
    141143
    142   EVP_MD_CTX_destroy (handle);
    143   return ret;
     144  kcapi_md_destroy(handle);
     145  return (hash_length == SHA_DIGEST_LENGTH);
    144146}
    145147
    146148/***
  • configure.ac

    a b  
    131131
    132132AS_IF([test "x$want_crypto" = "xauto" -o "x$want_crypto" = "xopenssl"], [
    133133    PKG_CHECK_MODULES(OPENSSL, [openssl >= $OPENSSL_MINIMUM],
    134         [want_crypto="openssl"; CRYPTO_PKG="openssl"; CRYPTO_CFLAGS="$OPENSSL_CFLAGS"; CRYPTO_LIBS="$OPENSSL_LIBS"],
     134        [want_crypto="openssl"; CRYPTO_PKG="openssl"; CRYPTO_CFLAGS="$OPENSSL_CFLAGS"; CRYPTO_LIBS="$OPENSSL_LIBS -lkcapi"],
    135135        [AS_IF([test "x$want_crypto" = "xopenssl"],
    136136            [AC_MSG_ERROR([OpenSSL support requested, but library not found.])]
    137137        )]