replace uses of OAAT hash in all its variants by NZAT (mksh internal) or NZAAT (all others)

This commit is contained in:
tg
2011-07-06 22:22:02 +00:00
parent fe2c0221b3
commit 3ef67e3296
7 changed files with 103 additions and 103 deletions

View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.471 2011/07/05 20:12:15 tg Exp $ # $MirOS: src/bin/mksh/check.t,v 1.472 2011/07/06 22:21:54 tg Exp $
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $ # $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
@ -25,7 +25,7 @@
# http://www.research.att.com/~gsf/public/ifs.sh # http://www.research.att.com/~gsf/public/ifs.sh
expected-stdout: expected-stdout:
@(#)MIRBSD KSH R40 2011/07/05 @(#)MIRBSD KSH R40 2011/07/06
description: description:
Check version of shell. Check version of shell.
stdin: stdin:
@ -6556,9 +6556,10 @@ description:
stdin: stdin:
typeset -i8 foo=10 typeset -i8 foo=10
bar=baz bar=baz
print ${bar@#} ${baz@#} . unset baz
print ${foo@#} ${bar@#} ${baz@#} .
expected-stdout: expected-stdout:
57F1BA9A 04808901 . 3BA2B200 9072C3DA 00000001 .
--- ---
name: varexpand-null-1 name: varexpand-null-1
description: description:

View File

@ -1,5 +1,5 @@
# $Id$ # $Id$
# $MirOS: src/bin/mksh/dot.mkshrc,v 1.62 2011/07/05 20:19:17 tg Exp $ # $MirOS: src/bin/mksh/dot.mkshrc,v 1.63 2011/07/06 22:21:56 tg Exp $
#- #-
# Copyright (c) 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011 # Copyright (c) 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011
# Thorsten Glaser <tg@mirbsd.org> # Thorsten Glaser <tg@mirbsd.org>
@ -294,9 +294,9 @@ function Lb64encode {
done done
(( u )) || set -U (( u )) || set -U
} }
# DJB cdb hash (not via stdio, for speed) # mksh NUL counting, never zero
typeset -Z11 -Uui16 Lcdbhash_result typeset -Z11 -Uui16 Lnzathash_v
function Lnzathash_add { function Lnzathash_add {
[[ -o utf8-mode ]]; local u=$? [[ -o utf8-mode ]]; local u=$?
set +U set +U
@ -309,53 +309,32 @@ function Lcdbhash_add {
fi fi
local -i i=0 n=${#s[*]} local -i i=0 n=${#s[*]}
while (( i < n )); do while (( i < n )); do
((# Lnzathash_v = (Lnzathash_v + s[i++] + 1) * 1025 ))
((# Lnzathash_v ^= Lnzathash_v >> 6 )) ((# Lnzathash_v ^= Lnzathash_v >> 6 ))
done done
(( u )) || set -U (( u )) || set -U
} }
function Lcdbhash { function Lnzaathash_end {
Lcdbhash_result=5381 ((# Lnzathash_v += Lnzathash_v << 3 ))
Lcdbhash_add "$@" ((# Lnzathash_v = (Lnzathash_v ^
(Lnzathash_v >> 11)) * 32769 ))
print ${Lnzathash_v#16#} print ${Lnzathash_v#16#}
} }
function Lnzaathash {
# Jenkins one-at-a-time hash (not via stdio, for speed) Lnzathash_v=0
typeset -Z11 -Uui16 Loaathash_result Lnzathash_add "$@"
function Loaathash_add { Lnzaathash_end
[[ -o utf8-mode ]]; local u=$? }
set +U function Lnzathash {
local s Lnzathash_v=0
if (( $# )); then Lnzathash_add "$@"
read -raN-1 s <<<"$*" if (( Lnzathash_v )); then
Lnzaathash_end Lnzaathash_end
else else
Lnzathash_v=1
print ${Lnzathash_v#16#} print ${Lnzathash_v#16#}
fi
local -i i=0 n=${#s[*]}
while (( i < n )); do
((# Loaathash_result = (Loaathash_result + s[i++]) *
1025 ))
((# Loaathash_result ^= Loaathash_result >> 6 ))
done
(( u )) || set -U
}
function Loaathash_do {
Loaathash_add "$@"
((# Loaathash_result += Loaathash_result << 3 ))
((# Loaathash_result = (Loaathash_result ^
(Loaathash_result >> 11)) * 32769 ))
print ${Loaathash_result#16#}
}
function Loaathash {
Loaathash_result=0
Loaathash_do "$@"
}
function Loaathash1 {
Loaathash_result=0x100
fi fi
} }

10
main.c
View File

@ -33,7 +33,7 @@
#include <locale.h> #include <locale.h>
#endif #endif
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.194 2011/07/02 17:57:39 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/main.c,v 1.195 2011/07/06 22:21:57 tg Exp $");
extern char **environ; extern char **environ;
@ -131,12 +131,12 @@ rndsetup(void)
/* introduce variation */ /* introduce variation */
gettimeofday(&bufptr->tv, &bufptr->tz); gettimeofday(&bufptr->tv, &bufptr->tz);
oaat1_init_impl(h); NZATInit(h);
/* variation through pid, ppid, and the works */ /* variation through pid, ppid, and the works */
oaat1_addmem_impl(h, &rndsetupstate, sizeof(rndsetupstate)); NZATUpdateMem(h, &rndsetupstate, sizeof(rndsetupstate));
/* some variation, some possibly entropy, depending on OE */ /* some variation, some possibly entropy, depending on OE */
oaat1_addmem_impl(h, bufptr, sizeof(*bufptr)); NZATUpdateMem(h, bufptr, sizeof(*bufptr));
oaat1_fini_impl(h); NZAATFinish(h);
afree(cp, APERM); afree(cp, APERM);
return ((mksh_uari_t)h); return ((mksh_uari_t)h);

8
misc.c
View File

@ -29,7 +29,7 @@
#include <grp.h> #include <grp.h>
#endif #endif
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.168 2011/06/12 15:37:08 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/misc.c,v 1.169 2011/07/06 22:21:57 tg Exp $");
/* type bits for unsigned char */ /* type bits for unsigned char */
unsigned char chtypes[UCHAR_MAX + 1]; unsigned char chtypes[UCHAR_MAX + 1];
@ -1867,9 +1867,9 @@ chvt(const char *fn)
{ {
register uint32_t h; register uint32_t h;
oaat1_init_impl(h); NZATInit(h);
oaat1_addmem_impl(h, &rndsetupstate, sizeof(rndsetupstate)); NZATUpdateMem(h, &rndsetupstate, sizeof(rndsetupstate));
oaat1_fini_impl(h); NZAATFinish(h);
rndset((long)h); rndset((long)h);
} }
chvt_reinit(); chvt_reinit();

8
mksh.1
View File

@ -1,4 +1,4 @@
.\" $MirOS: src/bin/mksh/mksh.1,v 1.267 2011/07/05 20:19:18 tg Exp $ .\" $MirOS: src/bin/mksh/mksh.1,v 1.268 2011/07/06 22:21:58 tg Exp $
.\" $OpenBSD: ksh.1,v 1.140 2011/04/23 10:14:59 sobrado Exp $ .\" $OpenBSD: ksh.1,v 1.140 2011/04/23 10:14:59 sobrado Exp $
.\"- .\"-
.\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, .\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
@ -72,7 +72,7 @@
.\" with -mandoc, it might implement .Mx itself, but we want to .\" with -mandoc, it might implement .Mx itself, but we want to
.\" use our own definition. And .Dd must come *first*, always. .\" use our own definition. And .Dd must come *first*, always.
.\" .\"
.Dd $Mdocdate: July 5 2011 $ .Dd $Mdocdate: July 6 2011 $
.\" .\"
.\" Check which macro package we use .\" Check which macro package we use
.\" .\"
@ -1632,8 +1632,8 @@ Cannot be applied to a vector.
.It Pf ${ Ns Ar name Ns @#} .It Pf ${ Ns Ar name Ns @#}
The internal hash of the expansion of The internal hash of the expansion of
.Ar name . .Ar name .
At the moment, this is OAAT1 (Bob Jenkins' one-at-a-time hash with At the moment, this is NZAT (a never-zero 32-bit hash based on
an initialisation value of 0x00000100), but this is not set. Bob Jenkins' one-at-a-time hash), but this is not set.
This is the hash the shell uses internally for its associative arrays. This is the hash the shell uses internally for its associative arrays.
.El .El
.Pp .Pp

72
sh.h
View File

@ -9,28 +9,28 @@
/* $OpenBSD: tty.h,v 1.5 2004/12/20 11:34:26 otto Exp $ */ /* $OpenBSD: tty.h,v 1.5 2004/12/20 11:34:26 otto Exp $ */
/*- /*-
* Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 * Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
* Thorsten Glaser <tg@mirbsd.org> * Thorsten Glaser <tg@mirbsd.org>
* *
* Provided that these terms and disclaimer and all copyright notices * Provided that these terms and disclaimer and all copyright notices
* are retained or reproduced in an accompanying document, permission * are retained or reproduced in an accompanying document, permission
* is granted to deal in this work without restriction, including un- * is granted to deal in this work without restriction, including un
* limited rights to use, publicly perform, distribute, sell, modify, * limited rights to use, publicly perform, distribute, sell, modify,
* merge, give away, or sublicence. * merge, give away, or sublicence.
* *
* This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to * This work is provided AS IS and WITHOUT WARRANTY of any kind, to
* the utmost extent permitted by applicable law, neither express nor * the utmost extent permitted by applicable law, neither express nor
* implied; without malicious intent or gross negligence. In no event * implied; without malicious intent or gross negligence. In no event
* may a licensor, author or contributor be held liable for indirect, * may a licensor, author or contributor be held liable for indirect,
* direct, other damage, loss, or other issues arising in any way out * direct, other damage, loss, or other issues arising in any way out
* of dealing in the work, even if advised of the possibility of such * of dealing in the work, even if advised of the possibility of such
* damage or existence of a defect, except proven that it results out * damage or existence of a defect, except proven that it results out
* of said person's immediate fault when using the work as intended. * of said persons immediate fault when using the work as intended.
*/ */
#ifdef __dietlibc__ #ifdef __dietlibc__
/* XXX imake style */ /* XXX imake style */
#define _BSD_SOURCE /* live, BSD, live! */ #define _BSD_SOURCE /* live, BSD, live */
#endif #endif
#if HAVE_SYS_PARAM_H #if HAVE_SYS_PARAM_H
@ -151,9 +151,9 @@
#endif #endif
#ifdef EXTERN #ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.482 2011/07/05 20:12:19 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/sh.h,v 1.483 2011/07/06 22:22:00 tg Exp $");
#endif #endif
#define MKSH_VERSION "R40 2011/07/05" #define MKSH_VERSION "R40 2011/07/06"
#ifndef MKSH_INCLUDES_ONLY #ifndef MKSH_INCLUDES_ONLY
@ -1465,36 +1465,56 @@ EXTERN struct timeval j_usrtime, j_systime;
'+', (unsigned long)(cnst)); \ '+', (unsigned long)(cnst)); \
} while (/* CONSTCOND */ 0) } while (/* CONSTCOND */ 0)
/* Bob Jenkins' one-at-a-time hash, with better start value */
#define oaat1_init_impl(h) do { \ /* NZAT/NZAAT hashes based on Bob Jenkins' one-at-a-time hash */
(h) = 0x100; \
/* From: src/kern/include/nzat.h,v 1.1 2011/07/06 22:18:52 tg Exp $ */
#define NZATInit(h) do { \
(h) = 0; \
} while (/* CONSTCOND */ 0) } while (/* CONSTCOND */ 0)
#define oaat1_addmem_impl(h, buf, len) do { \
register const uint8_t *oaat1_addmem_p = (const void *)(buf); \ #define NZATUpdateByte(h,b) do { \
register size_t oaat1_addmem_n = (len); \ (h) += (uint8_t)(b); \
\ ++(h); \
while (oaat1_addmem_n--) { \
(h) += *oaat1_addmem_p++; \
(h) += (h) << 10; \ (h) += (h) << 10; \
(h) ^= (h) >> 6; \ (h) ^= (h) >> 6; \
} \
} while (/* CONSTCOND */ 0) } while (/* CONSTCOND */ 0)
#define oaat1_addstr_impl(h, s) do { \
register const uint8_t *oaat1_addstr_p = (const void *)(s); \ #define NZATUpdateMem(h,p,z) do { \
register uint8_t oaat1_addstr_c; \ register const uint8_t *NZATUpdateMem_p; \
register size_t NZATUpdateMem_z = (z); \
\ \
while ((oaat1_addstr_c = *oaat1_addstr_p++)) { \ NZATUpdateMem_p = (const void *)(p); \
h += oaat1_addstr_c; \ while (NZATUpdateMem_z--) \
(h) += (h) << 10; \ NZATUpdateByte((h), *NZATUpdateMem_p++); \
(h) ^= (h) >> 6; \
} \
} while (/* CONSTCOND */ 0) } while (/* CONSTCOND */ 0)
#define oaat1_fini_impl(h) do { \
#define NZATUpdateString(h,s) do { \
register const char *NZATUpdateString_s; \
register uint8_t NZATUpdateString_c; \
\
NZATUpdateString_s = (const void *)(s); \
while ((NZATUpdateString_c = *NZATUpdateString_s++)) \
NZATUpdateByte((h), NZATUpdateString_c); \
} while (/* CONSTCOND */ 0)
/* not zero after termination */
#define NZATFinish(h) do { \
if ((h) == 0) \
++(h); \
else \
NZAATFinish(h); \
} while (/* CONSTCOND */ 0)
/* NULs zählen an allen Teilen */
#define NZAATFinish(h) do { \
(h) += (h) << 3; \ (h) += (h) << 3; \
(h) ^= (h) >> 11; \ (h) ^= (h) >> 11; \
(h) += (h) << 15; \ (h) += (h) << 15; \
} while (/* CONSTCOND */ 0) } while (/* CONSTCOND */ 0)
/* lalloc.c */ /* lalloc.c */
void ainit(Area *); void ainit(Area *);
void afreeall(Area *); void afreeall(Area *);

20
var.c
View File

@ -26,7 +26,7 @@
#include <sys/sysctl.h> #include <sys/sysctl.h>
#endif #endif
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.128 2011/07/05 20:12:20 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/var.c,v 1.129 2011/07/06 22:22:02 tg Exp $");
/*- /*-
* Variables * Variables
@ -1496,9 +1496,9 @@ hash(const void *s)
{ {
register uint32_t h; register uint32_t h;
oaat1_init_impl(h); NZATInit(h);
oaat1_addstr_impl(h, s); NZATUpdateString(h, s);
oaat1_fini_impl(h); NZATFinish(h);
return (h); return (h);
} }
@ -1507,9 +1507,9 @@ rndset(long v)
{ {
register uint32_t h; register uint32_t h;
oaat1_init_impl(h); NZATInit(h);
oaat1_addmem_impl(h, &lcg_state, sizeof(lcg_state)); NZATUpdateMem(h, &lcg_state, sizeof(lcg_state));
oaat1_addmem_impl(h, &v, sizeof(v)); NZATUpdateMem(h, &v, sizeof(v));
#if defined(arc4random_pushb_fast) || defined(MKSH_A4PB) #if defined(arc4random_pushb_fast) || defined(MKSH_A4PB)
/* /*
@ -1518,16 +1518,16 @@ rndset(long v)
* user requested us to use the old functions * user requested us to use the old functions
*/ */
lcg_state = h; lcg_state = h;
oaat1_fini_impl(lcg_state); NZAATFinish(lcg_state);
#if defined(arc4random_pushb_fast) #if defined(arc4random_pushb_fast)
arc4random_pushb_fast(&lcg_state, sizeof(lcg_state)); arc4random_pushb_fast(&lcg_state, sizeof(lcg_state));
lcg_state = arc4random(); lcg_state = arc4random();
#else #else
lcg_state = arc4random_pushb(&lcg_state, sizeof(lcg_state)); lcg_state = arc4random_pushb(&lcg_state, sizeof(lcg_state));
#endif #endif
oaat1_addmem_impl(h, &lcg_state, sizeof(lcg_state)); NZATUpdateMem(h, &lcg_state, sizeof(lcg_state));
#endif #endif
oaat1_fini_impl(h); NZAATFinish(h);
lcg_state = h; lcg_state = h;
} }