HKDF (does not work yet)
[oweals/gnunet.git] / src / include / gnunet_crypto_lib.h
index e1eb0f28d1e7d7364f47473e41c9f6e722da7c20..479e0e42dd6030e1c1931d9197b798667400a7b7 100644 (file)
@@ -335,7 +335,7 @@ int GNUNET_CRYPTO_hash_from_string (const char *enc,
  *
  * @param a some hash code
  * @param b some hash code
- * @return number between 0 and 65536
+ * @return number between 0 and UINT32_MAX
  */
 uint32_t GNUNET_CRYPTO_hash_distance_u32 (const GNUNET_HashCode * a,
                                          const GNUNET_HashCode * b);
@@ -353,6 +353,21 @@ void GNUNET_CRYPTO_hash (const void *block,
                          GNUNET_HashCode * ret);
 
 
+/**
+ * Calculate HMAC of a message (RFC 2104)
+ *
+ * @param key secret key
+ * @param plaintext input plaintext
+ * @param plaintext_len length of plaintext
+ * @param hmac where to store the hmac
+ */
+void 
+GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AesSessionKey *key,
+                   const void *plaintext,
+                   size_t plaintext_len,
+                   GNUNET_HashCode *hmac);
+
+
 /**
  * Function called once the hash computation over the
  * specified file has completed.
@@ -496,6 +511,27 @@ int GNUNET_CRYPTO_hash_xorcmp (const GNUNET_HashCode * h1,
                                const GNUNET_HashCode * target);
 
 
+/**
+ * @brief Derive key
+ * @param xtr_algo hash algorithm for the extraction phase, GCRY_MD_...
+ * @param prf_algo hash algorithm for the expansion phase, GCRY_MD_...
+ * @param xts salt
+ * @param xts_len length of xts
+ * @param skm source key material
+ * @param skm_len length of skm
+ * @param ctx context info
+ * @param ctx_len length of ctx
+ * @param out_len desired length of the derived key
+ * @param result buffer for the derived key, allocated by caller
+ * @return GNUNET_YES on success
+ */
+int
+GNUNET_CRYPTO_hkdf (int xtr_algo, int prf_algo, const void *xts,
+    const size_t xts_len, const void *skm, const size_t skm_len,
+    const void *ctx, const size_t ctx_len, const unsigned long long out_len,
+    void *result);
+
+
 /**
  * Create a new private key. Caller must free return value.
  *