replace uses of OAAT hash in all its variants by NZAT (mksh internal) or NZAAT (all others)
This commit is contained in:
parent
fe2c0221b3
commit
3ef67e3296
9
check.t
9
check.t
|
@ -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: 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 $
|
||||
|
@ -25,7 +25,7 @@
|
|||
# http://www.research.att.com/~gsf/public/ifs.sh
|
||||
|
||||
expected-stdout:
|
||||
@(#)MIRBSD KSH R40 2011/07/05
|
||||
@(#)MIRBSD KSH R40 2011/07/06
|
||||
description:
|
||||
Check version of shell.
|
||||
stdin:
|
||||
|
@ -6556,9 +6556,10 @@ description:
|
|||
stdin:
|
||||
typeset -i8 foo=10
|
||||
bar=baz
|
||||
print ${bar@#} ${baz@#} .
|
||||
unset baz
|
||||
print ${foo@#} ${bar@#} ${baz@#} .
|
||||
expected-stdout:
|
||||
57F1BA9A 04808901 .
|
||||
3BA2B200 9072C3DA 00000001 .
|
||||
---
|
||||
name: varexpand-null-1
|
||||
description:
|
||||
|
|
67
dot.mkshrc
67
dot.mkshrc
|
@ -1,5 +1,5 @@
|
|||
# $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
|
||||
# Thorsten Glaser <tg@mirbsd.org>
|
||||
|
@ -294,9 +294,9 @@ function Lb64encode {
|
|||
(( u )) || set -U
|
||||
}
|
||||
|
||||
# DJB cdb hash (not via stdio, for speed)
|
||||
typeset -Z11 -Uui16 Lcdbhash_result
|
||||
function Lcdbhash_add {
|
||||
# mksh NUL counting, never zero
|
||||
typeset -Z11 -Uui16 Lnzathash_v
|
||||
function Lnzathash_add {
|
||||
[[ -o utf8-mode ]]; local u=$?
|
||||
set +U
|
||||
local s
|
||||
|
@ -309,53 +309,32 @@ function Lcdbhash_add {
|
|||
local -i i=0 n=${#s[*]}
|
||||
|
||||
while (( i < n )); do
|
||||
((# Lcdbhash_result = (Lcdbhash_result * 33) ^ s[i++] ))
|
||||
((# Lnzathash_v = (Lnzathash_v + s[i++] + 1) * 1025 ))
|
||||
((# Lnzathash_v ^= Lnzathash_v >> 6 ))
|
||||
done
|
||||
|
||||
(( u )) || set -U
|
||||
}
|
||||
function Lcdbhash {
|
||||
Lcdbhash_result=5381
|
||||
Lcdbhash_add "$@"
|
||||
print ${Lcdbhash_result#16#}
|
||||
function Lnzaathash_end {
|
||||
((# Lnzathash_v += Lnzathash_v << 3 ))
|
||||
((# Lnzathash_v = (Lnzathash_v ^
|
||||
(Lnzathash_v >> 11)) * 32769 ))
|
||||
print ${Lnzathash_v#16#}
|
||||
}
|
||||
|
||||
# Jenkins one-at-a-time hash (not via stdio, for speed)
|
||||
typeset -Z11 -Uui16 Loaathash_result
|
||||
function Loaathash_add {
|
||||
[[ -o utf8-mode ]]; local u=$?
|
||||
set +U
|
||||
local s
|
||||
if (( $# )); then
|
||||
read -raN-1 s <<<"$*"
|
||||
unset s[${#s[*]}-1]
|
||||
function Lnzaathash {
|
||||
Lnzathash_v=0
|
||||
Lnzathash_add "$@"
|
||||
Lnzaathash_end
|
||||
}
|
||||
function Lnzathash {
|
||||
Lnzathash_v=0
|
||||
Lnzathash_add "$@"
|
||||
if (( Lnzathash_v )); then
|
||||
Lnzaathash_end
|
||||
else
|
||||
read -raN-1 s
|
||||
Lnzathash_v=1
|
||||
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
|
||||
Loaathash_do "$@"
|
||||
}
|
||||
|
||||
# strip comments (and leading/trailing whitespace if IFS is set) from
|
||||
|
|
10
main.c
10
main.c
|
@ -33,7 +33,7 @@
|
|||
#include <locale.h>
|
||||
#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;
|
||||
|
||||
|
@ -131,12 +131,12 @@ rndsetup(void)
|
|||
/* introduce variation */
|
||||
gettimeofday(&bufptr->tv, &bufptr->tz);
|
||||
|
||||
oaat1_init_impl(h);
|
||||
NZATInit(h);
|
||||
/* 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 */
|
||||
oaat1_addmem_impl(h, bufptr, sizeof(*bufptr));
|
||||
oaat1_fini_impl(h);
|
||||
NZATUpdateMem(h, bufptr, sizeof(*bufptr));
|
||||
NZAATFinish(h);
|
||||
|
||||
afree(cp, APERM);
|
||||
return ((mksh_uari_t)h);
|
||||
|
|
8
misc.c
8
misc.c
|
@ -29,7 +29,7 @@
|
|||
#include <grp.h>
|
||||
#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 */
|
||||
unsigned char chtypes[UCHAR_MAX + 1];
|
||||
|
@ -1867,9 +1867,9 @@ chvt(const char *fn)
|
|||
{
|
||||
register uint32_t h;
|
||||
|
||||
oaat1_init_impl(h);
|
||||
oaat1_addmem_impl(h, &rndsetupstate, sizeof(rndsetupstate));
|
||||
oaat1_fini_impl(h);
|
||||
NZATInit(h);
|
||||
NZATUpdateMem(h, &rndsetupstate, sizeof(rndsetupstate));
|
||||
NZAATFinish(h);
|
||||
rndset((long)h);
|
||||
}
|
||||
chvt_reinit();
|
||||
|
|
8
mksh.1
8
mksh.1
|
@ -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 $
|
||||
.\"-
|
||||
.\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
|
||||
|
@ -72,7 +72,7 @@
|
|||
.\" with -mandoc, it might implement .Mx itself, but we want to
|
||||
.\" 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
|
||||
.\"
|
||||
|
@ -1632,8 +1632,8 @@ Cannot be applied to a vector.
|
|||
.It Pf ${ Ns Ar name Ns @#}
|
||||
The internal hash of the expansion of
|
||||
.Ar name .
|
||||
At the moment, this is OAAT1 (Bob Jenkins' one-at-a-time hash with
|
||||
an initialisation value of 0x00000100), but this is not set.
|
||||
At the moment, this is NZAT (a never-zero 32-bit hash based on
|
||||
Bob Jenkins' one-at-a-time hash), but this is not set.
|
||||
This is the hash the shell uses internally for its associative arrays.
|
||||
.El
|
||||
.Pp
|
||||
|
|
84
sh.h
84
sh.h
|
@ -9,28 +9,28 @@
|
|||
/* $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>
|
||||
*
|
||||
* Provided that these terms and disclaimer and all copyright notices
|
||||
* 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,
|
||||
* 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
|
||||
* implied; without malicious intent or gross negligence. In no event
|
||||
* may a licensor, author or contributor be held liable for indirect,
|
||||
* 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
|
||||
* 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 person’s immediate fault when using the work as intended.
|
||||
*/
|
||||
|
||||
#ifdef __dietlibc__
|
||||
/* XXX imake style */
|
||||
#define _BSD_SOURCE /* live, BSD, live! */
|
||||
#define _BSD_SOURCE /* live, BSD, live❣ */
|
||||
#endif
|
||||
|
||||
#if HAVE_SYS_PARAM_H
|
||||
|
@ -151,9 +151,9 @@
|
|||
#endif
|
||||
|
||||
#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
|
||||
#define MKSH_VERSION "R40 2011/07/05"
|
||||
#define MKSH_VERSION "R40 2011/07/06"
|
||||
|
||||
#ifndef MKSH_INCLUDES_ONLY
|
||||
|
||||
|
@ -1465,36 +1465,56 @@ EXTERN struct timeval j_usrtime, j_systime;
|
|||
'+', (unsigned long)(cnst)); \
|
||||
} while (/* CONSTCOND */ 0)
|
||||
|
||||
/* Bob Jenkins' one-at-a-time hash, with better start value */
|
||||
#define oaat1_init_impl(h) do { \
|
||||
(h) = 0x100; \
|
||||
|
||||
/* NZAT/NZAAT hashes based on Bob Jenkins' one-at-a-time hash */
|
||||
|
||||
/* 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)
|
||||
#define oaat1_addmem_impl(h, buf, len) do { \
|
||||
register const uint8_t *oaat1_addmem_p = (const void *)(buf); \
|
||||
register size_t oaat1_addmem_n = (len); \
|
||||
\
|
||||
while (oaat1_addmem_n--) { \
|
||||
(h) += *oaat1_addmem_p++; \
|
||||
(h) += (h) << 10; \
|
||||
(h) ^= (h) >> 6; \
|
||||
} \
|
||||
|
||||
#define NZATUpdateByte(h,b) do { \
|
||||
(h) += (uint8_t)(b); \
|
||||
++(h); \
|
||||
(h) += (h) << 10; \
|
||||
(h) ^= (h) >> 6; \
|
||||
} while (/* CONSTCOND */ 0)
|
||||
#define oaat1_addstr_impl(h, s) do { \
|
||||
register const uint8_t *oaat1_addstr_p = (const void *)(s); \
|
||||
register uint8_t oaat1_addstr_c; \
|
||||
\
|
||||
while ((oaat1_addstr_c = *oaat1_addstr_p++)) { \
|
||||
h += oaat1_addstr_c; \
|
||||
(h) += (h) << 10; \
|
||||
(h) ^= (h) >> 6; \
|
||||
} \
|
||||
|
||||
#define NZATUpdateMem(h,p,z) do { \
|
||||
register const uint8_t *NZATUpdateMem_p; \
|
||||
register size_t NZATUpdateMem_z = (z); \
|
||||
\
|
||||
NZATUpdateMem_p = (const void *)(p); \
|
||||
while (NZATUpdateMem_z--) \
|
||||
NZATUpdateByte((h), *NZATUpdateMem_p++); \
|
||||
} while (/* CONSTCOND */ 0)
|
||||
#define oaat1_fini_impl(h) do { \
|
||||
(h) += (h) << 3; \
|
||||
(h) ^= (h) >> 11; \
|
||||
(h) += (h) << 15; \
|
||||
|
||||
#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) >> 11; \
|
||||
(h) += (h) << 15; \
|
||||
} while (/* CONSTCOND */ 0)
|
||||
|
||||
|
||||
/* lalloc.c */
|
||||
void ainit(Area *);
|
||||
void afreeall(Area *);
|
||||
|
|
20
var.c
20
var.c
|
@ -26,7 +26,7 @@
|
|||
#include <sys/sysctl.h>
|
||||
#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
|
||||
|
@ -1496,9 +1496,9 @@ hash(const void *s)
|
|||
{
|
||||
register uint32_t h;
|
||||
|
||||
oaat1_init_impl(h);
|
||||
oaat1_addstr_impl(h, s);
|
||||
oaat1_fini_impl(h);
|
||||
NZATInit(h);
|
||||
NZATUpdateString(h, s);
|
||||
NZATFinish(h);
|
||||
return (h);
|
||||
}
|
||||
|
||||
|
@ -1507,9 +1507,9 @@ rndset(long v)
|
|||
{
|
||||
register uint32_t h;
|
||||
|
||||
oaat1_init_impl(h);
|
||||
oaat1_addmem_impl(h, &lcg_state, sizeof(lcg_state));
|
||||
oaat1_addmem_impl(h, &v, sizeof(v));
|
||||
NZATInit(h);
|
||||
NZATUpdateMem(h, &lcg_state, sizeof(lcg_state));
|
||||
NZATUpdateMem(h, &v, sizeof(v));
|
||||
|
||||
#if defined(arc4random_pushb_fast) || defined(MKSH_A4PB)
|
||||
/*
|
||||
|
@ -1518,16 +1518,16 @@ rndset(long v)
|
|||
* user requested us to use the old functions
|
||||
*/
|
||||
lcg_state = h;
|
||||
oaat1_fini_impl(lcg_state);
|
||||
NZAATFinish(lcg_state);
|
||||
#if defined(arc4random_pushb_fast)
|
||||
arc4random_pushb_fast(&lcg_state, sizeof(lcg_state));
|
||||
lcg_state = arc4random();
|
||||
#else
|
||||
lcg_state = arc4random_pushb(&lcg_state, sizeof(lcg_state));
|
||||
#endif
|
||||
oaat1_addmem_impl(h, &lcg_state, sizeof(lcg_state));
|
||||
NZATUpdateMem(h, &lcg_state, sizeof(lcg_state));
|
||||
#endif
|
||||
|
||||
oaat1_fini_impl(h);
|
||||
NZAATFinish(h);
|
||||
lcg_state = h;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue