Skip to content

Commit

Permalink
Expose a bit of lhash/conf for Ruby (#1987)
Browse files Browse the repository at this point in the history
This extends upon #1986.

We do have all the necessary support for "LHASH", it's just been renamed
and made internal by upstream: b8441ac. Ruby's CONF module happens
to have a dependency on a couple of LHASH macros OpenSSL created
and the non-opaqueness of CONF.
Although we aren't likely to be supporting CONF files for the time
being, this change seems to reasonable for enough us to maintain so we
can get a better build/patch for Ruby. We still fail most CONF related
tests in Ruby, so we'll have to work around those. But this commit lets
us gracefully build with the underlying C code for Ruby CONF without any
AWS-LC specific logic.

### Testing:
Verified that this passes the build for Ruby

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license and the ISC license.
  • Loading branch information
samuel40791765 authored Nov 16, 2024
1 parent cfe86a3 commit 0d4dab7
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
4 changes: 0 additions & 4 deletions crypto/conf/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ extern "C" {

DEFINE_LHASH_OF(CONF_VALUE)

struct conf_st {
LHASH_OF(CONF_VALUE) *data;
};

// CONF_VALUE_new returns a freshly allocated and zeroed |CONF_VALUE|.
CONF_VALUE *CONF_VALUE_new(void);

Expand Down
1 change: 0 additions & 1 deletion crypto/lhash/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ typedef int (*lhash_cmp_func_helper)(lhash_cmp_func func, const void *a,
typedef uint32_t (*lhash_hash_func)(const void *a);
typedef uint32_t (*lhash_hash_func_helper)(lhash_hash_func func, const void *a);

typedef struct lhash_st _LHASH;

// OPENSSL_lh_new returns a new, empty hash table or NULL on error.
OPENSSL_EXPORT _LHASH *OPENSSL_lh_new(lhash_hash_func hash,
Expand Down
4 changes: 4 additions & 0 deletions crypto/lhash/lhash.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,3 +347,7 @@ void OPENSSL_lh_doall_arg(_LHASH *lh, void (*func)(void *, void *), void *arg) {
// resizing is done here.
lh_maybe_resize(lh);
}

void lh_doall_arg(_LHASH *lh, void (*func)(void *, void *), void *arg) {
OPENSSL_lh_doall_arg(lh, func, arg);
}
3 changes: 3 additions & 0 deletions include/openssl/conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ struct conf_value_st {
DEFINE_STACK_OF(CONF_VALUE)
DECLARE_LHASH_OF(CONF_VALUE)

struct conf_st {
LHASH_OF(CONF_VALUE) *data;
};

// NCONF_new returns a fresh, empty |CONF|, or NULL on error. The |method|
// argument must be NULL.
Expand Down
13 changes: 13 additions & 0 deletions include/openssl/lhash.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
extern "C" {
#endif

typedef struct lhash_st _LHASH;

// lhash is an internal library and not exported for use outside BoringSSL. This
// header is provided for compatibility with code that expects OpenSSL.
Expand All @@ -73,6 +74,18 @@ extern "C" {
#define LHASH_OF(type) struct lhash_st_##type
#define DECLARE_LHASH_OF(type) LHASH_OF(type);

OPENSSL_EXPORT void lh_doall_arg(_LHASH *lh, void (*func)(void *, void *),
void *arg);

// These two macros are the bare minimum of |LHASH| macros downstream consumers
// use.
#define IMPLEMENT_LHASH_DOALL_ARG_FN(name, o_type, a_type) \
void name##_LHASH_DOALL_ARG(void *arg1, void *arg2) { \
o_type *a = arg1; \
a_type *b = arg2; \
name##_doall_arg(a, b); }
#define LHASH_DOALL_ARG_FN(name) name##_LHASH_DOALL_ARG


#if defined(__cplusplus)
} // extern C
Expand Down

0 comments on commit 0d4dab7

Please sign in to comment.