Wireshark  2.9.0-477-g68ec514b
The Wireshark network protocol analyzer
wsgcrypt.h
1 /* wsgcrypt.h
2  *
3  * Wrapper around libgcrypt's include file gcrypt.h.
4  * For libgcrypt 1.5.0, including gcrypt.h directly brings up lots of
5  * compiler warnings about deprecated definitions.
6  * Try to work around these warnings to ensure a clean build with -Werror.
7  *
8  * Wireshark - Network traffic analyzer
9  * By Gerald Combs <gerald@wireshark.org>
10  * Copyright 2007 Gerald Combs
11  *
12  * SPDX-License-Identifier: GPL-2.0-or-later
13  */
14 
15 #ifndef __WSGCRYPT_H__
16 #define __WSGCRYPT_H__
17 
18 #include <ws_diag_control.h>
19 #include "ws_symbol_export.h"
20 #include <glib.h>
21 
22 DIAG_OFF(deprecated-declarations)
23 
24 #include <gcrypt.h>
25 
26 DIAG_ON(deprecated-declarations)
27 
28 #define HASH_MD5_LENGTH 16
29 #define HASH_SHA1_LENGTH 20
30 #define HASH_SHA2_224_LENGTH 28
31 #define HASH_SHA2_256_LENGTH 32
32 #define HASH_SHA2_384_LENGTH 48
33 #define HASH_SHA2_512_LENGTH 64
34 
35 /* Convenience function to calculate the HMAC from the data in BUFFER
36  of size LENGTH with key KEY of size KEYLEN using the algorithm ALGO avoiding the creating of a
37  hash object. The hash is returned in the caller provided buffer
38  DIGEST which must be large enough to hold the digest of the given
39  algorithm. */
40 WS_DLL_PUBLIC gcry_error_t ws_hmac_buffer(int algo, void *digest, const void *buffer, size_t length, const void *key, size_t keylen);
41 
42 /* Convenience function to encrypt 8 bytes in BUFFER with DES using the 56 bits KEY expanded to
43  64 bits as key, encrypted data is returned in OUTPUT which must be at least 8 bytes large */
44 WS_DLL_PUBLIC void crypt_des_ecb(guint8 *output, const guint8 *buffer, const guint8 *key56);
45 
46 /* Convenience function for RSA decryption. Returns decrypted length on success, 0 on failure */
47 WS_DLL_PUBLIC size_t rsa_decrypt_inplace(const guint len, guchar* data, gcry_sexp_t pk, gboolean pkcs1_padding, char **err);
48 
62 WS_DLL_PUBLIC gcry_error_t
63 hkdf_expand(int hashalgo, const guint8 *prk, guint prk_len, const guint8 *info, guint info_len,
64  guint8 *out, guint out_len);
65 
66 /*
67  * Calculate HKDF-Extract(salt, IKM) -> PRK according to RFC 5869.
68  * Caller MUST ensure that 'prk' is large enough to store the digest from hash
69  * algorithm 'hashalgo' (e.g. 32 bytes for SHA-256).
70  */
71 static inline gcry_error_t
72 hkdf_extract(int hashalgo, const guint8 *salt, size_t salt_len, const guint8 *ikm, size_t ikm_len, guint8 *prk)
73 {
74  /* PRK = HMAC-Hash(salt, IKM) where salt is key, and IKM is input. */
75  return ws_hmac_buffer(hashalgo, prk, ikm, ikm_len, salt, salt_len);
76 }
77 
78 
79 #endif /* __WSGCRYPT_H__ */
Definition: file-pcapng.c:177
Definition: mcast_stream.h:30