mirror of
https://github.com/janet-lang/janet
synced 2024-11-28 11:09:54 +00:00
Allow disabling keyed hash function (prf) in conf
In some cases, one might want to disable what is currently SipHash for speed / better security mechansims. For example, using red black trees for caches rather than hash tables.
This commit is contained in:
parent
3d117804dd
commit
23c7c3bf1c
@ -62,6 +62,7 @@ conf.set('JANET_NO_PEG', not get_option('peg'))
|
|||||||
conf.set('JANET_REDUCED_OS', get_option('reduced_os'))
|
conf.set('JANET_REDUCED_OS', get_option('reduced_os'))
|
||||||
conf.set('JANET_NO_TYPED_ARRAY', not get_option('typed_array'))
|
conf.set('JANET_NO_TYPED_ARRAY', not get_option('typed_array'))
|
||||||
conf.set('JANET_NO_INT_TYPES', not get_option('int_types'))
|
conf.set('JANET_NO_INT_TYPES', not get_option('int_types'))
|
||||||
|
conf.set('JANET_NO_PRF', not get_option('prf'))
|
||||||
conf.set('JANET_RECURSION_GUARD', get_option('recursion_guard'))
|
conf.set('JANET_RECURSION_GUARD', get_option('recursion_guard'))
|
||||||
conf.set('JANET_MAX_PROTO_DEPTH', get_option('max_proto_depth'))
|
conf.set('JANET_MAX_PROTO_DEPTH', get_option('max_proto_depth'))
|
||||||
conf.set('JANET_MAX_MACRO_EXPAND', get_option('max_macro_expand'))
|
conf.set('JANET_MAX_MACRO_EXPAND', get_option('max_macro_expand'))
|
||||||
|
@ -10,6 +10,7 @@ option('assembler', type : 'boolean', value : true)
|
|||||||
option('peg', type : 'boolean', value : true)
|
option('peg', type : 'boolean', value : true)
|
||||||
option('typed_array', type : 'boolean', value : true)
|
option('typed_array', type : 'boolean', value : true)
|
||||||
option('int_types', type : 'boolean', value : true)
|
option('int_types', type : 'boolean', value : true)
|
||||||
|
option('prf', type : 'boolean', value : true)
|
||||||
|
|
||||||
option('recursion_guard', type : 'integer', min : 10, max : 8000, value : 1024)
|
option('recursion_guard', type : 'integer', min : 10, max : 8000, value : 1024)
|
||||||
option('max_proto_depth', type : 'integer', min : 10, max : 8000, value : 200)
|
option('max_proto_depth', type : 'integer', min : 10, max : 8000, value : 200)
|
||||||
|
@ -51,6 +51,7 @@
|
|||||||
/* #define JANET_NO_PEG */
|
/* #define JANET_NO_PEG */
|
||||||
/* #define JANET_NO_TYPED_ARRAY */
|
/* #define JANET_NO_TYPED_ARRAY */
|
||||||
/* #define JANET_NO_INT_TYPES */
|
/* #define JANET_NO_INT_TYPES */
|
||||||
|
/* #define JANET_NO_PRF */
|
||||||
/* #define JANET_OUT_OF_MEMORY do { printf("janet out of memory\n"); exit(1); } while (0) */
|
/* #define JANET_OUT_OF_MEMORY do { printf("janet out of memory\n"); exit(1); } while (0) */
|
||||||
/* #define JANET_RECURSION_GUARD 1024 */
|
/* #define JANET_RECURSION_GUARD 1024 */
|
||||||
/* #define JANET_MAX_PROTO_DEPTH 200 */
|
/* #define JANET_MAX_PROTO_DEPTH 200 */
|
||||||
|
@ -94,6 +94,18 @@ const char *const janet_status_names[16] = {
|
|||||||
"alive"
|
"alive"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifdef JANET_NO_PRF
|
||||||
|
|
||||||
|
int32_t janet_string_calchash(const uint8_t *str, int32_t len) {
|
||||||
|
const uint8_t *end = str + len;
|
||||||
|
uint32_t hash = 5381;
|
||||||
|
while (str < end)
|
||||||
|
hash = (hash << 5) + hash + *str++;
|
||||||
|
return (int32_t) hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Public domain siphash implementation sourced from:
|
Public domain siphash implementation sourced from:
|
||||||
|
|
||||||
@ -202,6 +214,8 @@ int32_t janet_string_calchash(const uint8_t *str, int32_t len) {
|
|||||||
return (int32_t)hash;
|
return (int32_t)hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Computes hash of an array of values */
|
/* Computes hash of an array of values */
|
||||||
int32_t janet_array_calchash(const Janet *array, int32_t len) {
|
int32_t janet_array_calchash(const Janet *array, int32_t len) {
|
||||||
const Janet *end = array + len;
|
const Janet *end = array + len;
|
||||||
|
@ -1302,8 +1302,10 @@ JANET_API int janet_verify(JanetFuncDef *def);
|
|||||||
JANET_API JanetBuffer *janet_pretty(JanetBuffer *buffer, int depth, int flags, Janet x);
|
JANET_API JanetBuffer *janet_pretty(JanetBuffer *buffer, int depth, int flags, Janet x);
|
||||||
|
|
||||||
/* Misc */
|
/* Misc */
|
||||||
JANET_API int janet_equals(Janet x, Janet y);
|
#ifndef JANET_NO_PRF
|
||||||
JANET_API void janet_init_hash_key(uint8_t key[16]);
|
JANET_API void janet_init_hash_key(uint8_t key[16]);
|
||||||
|
#endif
|
||||||
|
JANET_API int janet_equals(Janet x, Janet y);
|
||||||
JANET_API int32_t janet_hash(Janet x);
|
JANET_API int32_t janet_hash(Janet x);
|
||||||
JANET_API int janet_compare(Janet x, Janet y);
|
JANET_API int janet_compare(Janet x, Janet y);
|
||||||
JANET_API int janet_cstrcmp(JanetString str, const char *other);
|
JANET_API int janet_cstrcmp(JanetString str, const char *other);
|
||||||
|
Loading…
Reference in New Issue
Block a user