Make numerous improvements

- Python static hello world now 1.8mb
- Python static fully loaded now 10mb
- Python HTTPS client now uses MbedTLS
- Python REPL now completes import stmts
- Increase stack size for Python for now
- Begin synthesizing posixpath and ntpath
- Restore Python \N{UNICODE NAME} support
- Restore Python NFKD symbol normalization
- Add optimized code path for Intel SHA-NI
- Get more Python unit tests passing faster
- Get Python help() pagination working on NT
- Python hashlib now supports MbedTLS PBKDF2
- Make memcpy/memmove/memcmp/bcmp/etc. faster
- Add Mersenne Twister and Vigna to LIBC_RAND
- Provide privileged __printf() for error code
- Fix zipos opendir() so that it reports ENOTDIR
- Add basic chmod() implementation for Windows NT
- Add Cosmo's best functions to Python cosmo module
- Pin function trace indent depth to that of caller
- Show memory diagram on invalid access in MODE=dbg
- Differentiate stack overflow on crash in MODE=dbg
- Add stb_truetype and tools for analyzing font files
- Upgrade to UNICODE 13 and reduce its binary footprint
- COMPILE.COM now logs resource usage of build commands
- Start implementing basic poll() support on bare metal
- Set getauxval(AT_EXECFN) to GetModuleFileName() on NT
- Add descriptions to strerror() in non-TINY build modes
- Add COUNTBRANCH() macro to help with micro-optimizations
- Make error / backtrace / asan / memory code more unbreakable
- Add fast perfect C implementation of μ-Law and a-Law audio codecs
- Make strtol() functions consistent with other libc implementations
- Improve Linenoise implementation (see also github.com/jart/bestline)
- COMPILE.COM now suppresses stdout/stderr of successful build commands
This commit is contained in:
Justine Tunney 2021-09-27 22:58:51 -07:00
parent fa7b4f5bd1
commit 39bf41f4eb
806 changed files with 77494 additions and 63859 deletions

View file

@ -130,10 +130,7 @@ Compile for example as `gcc test.c libargon2.a -Isrc -o test`, if the program
below is named `test.c` and placed in the project's root directory.
```c
#include "argon2.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "third_party/argon2/argon2.h"
#define HASHLEN 32
#define SALTLEN 16

View file

@ -1,3 +1,11 @@
#include "libc/limits.h"
#include "libc/mem/mem.h"
#include "libc/str/str.h"
#include "third_party/argon2/argon2.h"
#include "third_party/argon2/core.h"
#include "third_party/argon2/encoding.h"
/* clang-format off */
/*
* Argon2 reference source code package - reference C implementations
*
@ -15,14 +23,6 @@
* software. If not, they may be obtained at the above URLs.
*/
#include <libc/isystem/string.h>
#include <libc/isystem/stdlib.h>
#include <libc/isystem/stdio.h>
#include "third_party/argon2/argon2.h"
#include "third_party/argon2/encoding.h"
#include "third_party/argon2/core.h"
const char *argon2_type2string(argon2_type type, int uppercase) {
switch (type) {
case Argon2_d:

View file

@ -1,30 +1,8 @@
/*
* Argon2 reference source code package - reference C implementations
*
* Copyright 2015
* Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves
*
* You may use this work under the terms of a Creative Commons CC0 1.0
* License/Waiver or the Apache Public License 2.0, at your option. The terms of
* these licenses can be found at:
*
* - CC0 1.0 Universal : https://creativecommons.org/publicdomain/zero/1.0
* - Apache 2.0 : https://www.apache.org/licenses/LICENSE-2.0
*
* You should have received a copy of both of these licenses along with this
* software. If not, they may be obtained at the above URLs.
*/
#ifndef ARGON2_H
#define ARGON2_H
#include <libc/isystem/stdint.h>
#include <libc/isystem/stddef.h>
#include <libc/isystem/limits.h>
#if defined(__cplusplus)
extern "C" {
#endif
#include "libc/literal.h"
COSMOPOLITAN_C_START_
/* clang-format off */
/* Symbols visibility control */
#ifdef A2_VISCTL
@ -430,8 +408,5 @@ ARGON2_PUBLIC size_t argon2_encodedlen(uint32_t t_cost, uint32_t m_cost,
uint32_t parallelism, uint32_t saltlen,
uint32_t hashlen, argon2_type type);
#if defined(__cplusplus)
}
#endif
COSMOPOLITAN_C_END_
#endif

View file

@ -1,67 +1,10 @@
/*
* Argon2 reference source code package - reference C implementations
*
* Copyright 2015
* Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves
*
* You may use this work under the terms of a Creative Commons CC0 1.0
* License/Waiver or the Apache Public License 2.0, at your option. The terms of
* these licenses can be found at:
*
* - CC0 1.0 Universal : https://creativecommons.org/publicdomain/zero/1.0
* - Apache 2.0 : https://www.apache.org/licenses/LICENSE-2.0
*
* You should have received a copy of both of these licenses along with this
* software. If not, they may be obtained at the above URLs.
*/
#ifndef PORTABLE_BLAKE2_IMPL_H
#define PORTABLE_BLAKE2_IMPL_H
#include "libc/str/str.h"
/* clang-format off */
#include <libc/isystem/stdint.h>
#include <libc/isystem/string.h>
#ifdef _WIN32
#define BLAKE2_INLINE __inline
#elif defined(__GNUC__) || defined(__clang__)
#define BLAKE2_INLINE __inline__
#else
#define BLAKE2_INLINE
#endif
/* Argon2 Team - Begin Code */
/*
Not an exhaustive list, but should cover the majority of modern platforms
Additionally, the code will always be correct---this is only a performance
tweak.
*/
#if (defined(__BYTE_ORDER__) && \
(__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)) || \
defined(__LITTLE_ENDIAN__) || defined(__ARMEL__) || defined(__MIPSEL__) || \
defined(__AARCH64EL__) || defined(__amd64__) || defined(__i386__) || \
defined(_M_IX86) || defined(_M_X64) || defined(_M_AMD64) || \
defined(_M_ARM)
#define NATIVE_LITTLE_ENDIAN
#endif
/* Argon2 Team - End Code */
static BLAKE2_INLINE uint32_t load32(const void *src) {
#if defined(NATIVE_LITTLE_ENDIAN)
uint32_t w;
memcpy(&w, src, sizeof w);
return w;
#else
const uint8_t *p = (const uint8_t *)src;
uint32_t w = *p++;
w |= (uint32_t)(*p++) << 8;
w |= (uint32_t)(*p++) << 16;
w |= (uint32_t)(*p++) << 24;
return w;
#endif
}
static BLAKE2_INLINE uint64_t load64(const void *src) {
#if defined(NATIVE_LITTLE_ENDIAN)
static inline uint64_t load64(const void *src) {
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
uint64_t w;
memcpy(&w, src, sizeof w);
return w;
@ -79,8 +22,8 @@ static BLAKE2_INLINE uint64_t load64(const void *src) {
#endif
}
static BLAKE2_INLINE void store32(void *dst, uint32_t w) {
#if defined(NATIVE_LITTLE_ENDIAN)
static inline void store32(void *dst, uint32_t w) {
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
memcpy(dst, &w, sizeof w);
#else
uint8_t *p = (uint8_t *)dst;
@ -94,8 +37,8 @@ static BLAKE2_INLINE void store32(void *dst, uint32_t w) {
#endif
}
static BLAKE2_INLINE void store64(void *dst, uint64_t w) {
#if defined(NATIVE_LITTLE_ENDIAN)
static inline void store64(void *dst, uint64_t w) {
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
memcpy(dst, &w, sizeof w);
#else
uint8_t *p = (uint8_t *)dst;
@ -117,7 +60,7 @@ static BLAKE2_INLINE void store64(void *dst, uint64_t w) {
#endif
}
static BLAKE2_INLINE uint64_t load48(const void *src) {
static inline uint64_t load48(const void *src) {
const uint8_t *p = (const uint8_t *)src;
uint64_t w = *p++;
w |= (uint64_t)(*p++) << 8;
@ -128,7 +71,7 @@ static BLAKE2_INLINE uint64_t load48(const void *src) {
return w;
}
static BLAKE2_INLINE void store48(void *dst, uint64_t w) {
static inline void store48(void *dst, uint64_t w) {
uint8_t *p = (uint8_t *)dst;
*p++ = (uint8_t)w;
w >>= 8;
@ -143,11 +86,11 @@ static BLAKE2_INLINE void store48(void *dst, uint64_t w) {
*p++ = (uint8_t)w;
}
static BLAKE2_INLINE uint32_t rotr32(const uint32_t w, const unsigned c) {
static inline uint32_t rotr32(const uint32_t w, const unsigned c) {
return (w >> c) | (w << (32 - c));
}
static BLAKE2_INLINE uint64_t rotr64(const uint64_t w, const unsigned c) {
static inline uint64_t rotr64(const uint64_t w, const unsigned c) {
return (w >> c) | (w << (64 - c));
}

View file

@ -1,28 +1,8 @@
/*
* Argon2 reference source code package - reference C implementations
*
* Copyright 2015
* Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves
*
* You may use this work under the terms of a Creative Commons CC0 1.0
* License/Waiver or the Apache Public License 2.0, at your option. The terms of
* these licenses can be found at:
*
* - CC0 1.0 Universal : https://creativecommons.org/publicdomain/zero/1.0
* - Apache 2.0 : https://www.apache.org/licenses/LICENSE-2.0
*
* You should have received a copy of both of these licenses along with this
* software. If not, they may be obtained at the above URLs.
*/
#ifndef PORTABLE_BLAKE2_H
#define PORTABLE_BLAKE2_H
#include <third_party/argon2/argon2.h>
#if defined(__cplusplus)
extern "C" {
#endif
#include "third_party/argon2/argon2.h"
COSMOPOLITAN_C_START_
/* clang-format off */
enum blake2b_constant {
BLAKE2B_BLOCKBYTES = 128,
@ -82,8 +62,5 @@ ARGON2_LOCAL int blake2b(void *out, size_t outlen, const void *in, size_t inlen,
ARGON2_LOCAL int blake2b_long(void *out, size_t outlen, const void *in, size_t inlen);
/* Argon2 Team - End Code */
#if defined(__cplusplus)
}
#endif
COSMOPOLITAN_C_END_
#endif

View file

@ -1,3 +1,10 @@
#include "libc/bits/bits.h"
#include "libc/limits.h"
#include "third_party/argon2/blake2-impl.h"
#include "third_party/argon2/blake2.h"
#include "third_party/argon2/core.h"
/* clang-format off */
/*
* Argon2 reference source code package - reference C implementations
*
@ -15,14 +22,6 @@
* software. If not, they may be obtained at the above URLs.
*/
#include <libc/isystem/stdint.h>
#include <libc/isystem/string.h>
#include <libc/isystem/stdio.h>
#include "third_party/argon2/blake2.h"
#include "third_party/argon2/blake2-impl.h"
#include "third_party/argon2/core.h" // for clear_internal_memory
static const uint64_t blake2b_IV[8] = {
UINT64_C(0x6a09e667f3bcc908), UINT64_C(0xbb67ae8584caa73b),
UINT64_C(0x3c6ef372fe94f82b), UINT64_C(0xa54ff53a5f1d36f1),
@ -44,29 +43,29 @@ static const unsigned int blake2b_sigma[12][16] = {
{14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3},
};
static BLAKE2_INLINE void blake2b_set_lastnode(blake2b_state *S) {
static inline void blake2b_set_lastnode(blake2b_state *S) {
S->f[1] = (uint64_t)-1;
}
static BLAKE2_INLINE void blake2b_set_lastblock(blake2b_state *S) {
static inline void blake2b_set_lastblock(blake2b_state *S) {
if (S->last_node) {
blake2b_set_lastnode(S);
}
S->f[0] = (uint64_t)-1;
}
static BLAKE2_INLINE void blake2b_increment_counter(blake2b_state *S,
static inline void blake2b_increment_counter(blake2b_state *S,
uint64_t inc) {
S->t[0] += inc;
S->t[1] += (S->t[0] < inc);
}
static BLAKE2_INLINE void blake2b_invalidate_state(blake2b_state *S) {
static inline void blake2b_invalidate_state(blake2b_state *S) {
clear_internal_memory(S, sizeof(*S)); /* wipe */
blake2b_set_lastblock(S); /* invalidate for further use */
}
static BLAKE2_INLINE void blake2b_init0(blake2b_state *S) {
static inline void blake2b_init0(blake2b_state *S) {
memset(S, 0, sizeof(*S));
memcpy(S->h, blake2b_IV, sizeof(S->h));
}
@ -82,7 +81,7 @@ int blake2b_init_param(blake2b_state *S, const blake2b_param *P) {
blake2b_init0(S);
/* IV XOR Parameter Block */
for (i = 0; i < 8; ++i) {
S->h[i] ^= load64(&p[i * sizeof(S->h[i])]);
S->h[i] ^= READ64LE(&p[i * sizeof(S->h[i])]);
}
S->outlen = P->digest_length;
return 0;
@ -170,7 +169,7 @@ static void blake2b_compress(blake2b_state *S, const uint8_t *block) {
unsigned int i, r;
for (i = 0; i < 16; ++i) {
m[i] = load64(block + i * sizeof(m[i]));
m[i] = READ64LE(block + i * sizeof(m[i]));
}
for (i = 0; i < 8; ++i) {

View file

@ -1,28 +1,11 @@
/*
* Argon2 reference source code package - reference C implementations
*
* Copyright 2015
* Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves
*
* You may use this work under the terms of a Creative Commons CC0 1.0
* License/Waiver or the Apache Public License 2.0, at your option. The terms of
* these licenses can be found at:
*
* - CC0 1.0 Universal : https://creativecommons.org/publicdomain/zero/1.0
* - Apache 2.0 : https://www.apache.org/licenses/LICENSE-2.0
*
* You should have received a copy of both of these licenses along with this
* software. If not, they may be obtained at the above URLs.
*/
#ifndef BLAKE_ROUND_MKA_H
#define BLAKE_ROUND_MKA_H
#include "third_party/argon2/blake2.h"
#include "third_party/argon2/blake2-impl.h"
#include "third_party/argon2/blake2.h"
/* clang-format off */
/* designed by the Lyra PHC team */
static BLAKE2_INLINE uint64_t fBlaMka(uint64_t x, uint64_t y) {
static inline uint64_t fBlaMka(uint64_t x, uint64_t y) {
const uint64_t m = UINT64_C(0xFFFFFFFF);
const uint64_t xy = (x & m) * (y & m);
return x + y + 2 * xy;
@ -53,4 +36,4 @@ static BLAKE2_INLINE uint64_t fBlaMka(uint64_t x, uint64_t y) {
G(v3, v4, v9, v14); \
} while ((void)0, 0)
#endif
#endif /* BLAKE_ROUND_MKA_H */

View file

@ -1,3 +1,9 @@
#include "libc/mem/mem.h"
#include "third_party/argon2/blake2-impl.h"
#include "third_party/argon2/blake2.h"
#include "third_party/argon2/core.h"
/* clang-format off */
/*
* Argon2 reference source code package - reference C implementations
*
@ -15,37 +21,6 @@
* software. If not, they may be obtained at the above URLs.
*/
#if defined __STDC_LIB_EXT1__
#define __STDC_WANT_LIB_EXT1__ 1
#endif
#define VC_GE_2005(version) (version >= 1400)
/* for explicit_bzero() on glibc */
#define _DEFAULT_SOURCE
#include <libc/isystem/stdio.h>
#include <libc/isystem/stdlib.h>
#include <libc/isystem/string.h>
#include "third_party/argon2/core.h"
#include "third_party/argon2/blake2.h"
#include "third_party/argon2/blake2-impl.h"
#if defined(__clang__)
#if __has_attribute(optnone)
#define NOT_OPTIMIZED __attribute__((optnone))
#endif
#elif defined(__GNUC__)
#define GCC_VERSION \
(__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
#if GCC_VERSION >= 40400
#define NOT_OPTIMIZED __attribute__((optimize("O0")))
#endif
#endif
#ifndef NOT_OPTIMIZED
#define NOT_OPTIMIZED
#endif
/***************Instance and Position constructors**********/
void init_block_value(block *b, uint8_t in) { memset(b->v, in, sizeof(b->v)); }
@ -113,32 +88,11 @@ void free_memory(const argon2_context *context, uint8_t *memory,
}
}
#if defined(__OpenBSD__)
#define HAVE_EXPLICIT_BZERO 1
#elif defined(__GLIBC__) && defined(__GLIBC_PREREQ)
#if __GLIBC_PREREQ(2,25)
#define HAVE_EXPLICIT_BZERO 1
#endif
#endif
void NOT_OPTIMIZED secure_wipe_memory(void *v, size_t n) {
#if defined(_MSC_VER) && VC_GE_2005(_MSC_VER) || defined(__MINGW32__)
SecureZeroMemory(v, n);
#elif defined memset_s
memset_s(v, n, 0, n);
#elif defined(HAVE_EXPLICIT_BZERO)
explicit_bzero(v, n);
#else
static void *(*const volatile memset_sec)(void *, int, size_t) = &memset;
memset_sec(v, 0, n);
#endif
}
/* Memory clear flag defaults to true. */
int FLAG_clear_internal_memory = 1;
void clear_internal_memory(void *v, size_t n) {
if (FLAG_clear_internal_memory && v) {
secure_wipe_memory(v, n);
explicit_bzero(v, n);
}
}
@ -551,7 +505,7 @@ void initial_hash(uint8_t *blockhash, argon2_context *context,
context->pwdlen);
if (context->flags & ARGON2_FLAG_CLEAR_PASSWORD) {
secure_wipe_memory(context->pwd, context->pwdlen);
explicit_bzero(context->pwd, context->pwdlen);
context->pwdlen = 0;
}
}
@ -572,7 +526,7 @@ void initial_hash(uint8_t *blockhash, argon2_context *context,
context->secretlen);
if (context->flags & ARGON2_FLAG_CLEAR_SECRET) {
secure_wipe_memory(context->secret, context->secretlen);
explicit_bzero(context->secret, context->secretlen);
context->secretlen = 0;
}
}

View file

@ -17,6 +17,7 @@
#ifndef ARGON2_CORE_H
#define ARGON2_CORE_H
/* clang-format off */
#include "third_party/argon2/argon2.h"

View file

@ -1,3 +1,10 @@
#include "libc/fmt/fmt.h"
#include "libc/limits.h"
#include "libc/str/str.h"
#include "third_party/argon2/core.h"
#include "third_party/argon2/encoding.h"
/* clang-format off */
/*
* Argon2 reference source code package - reference C implementations
*
@ -15,13 +22,6 @@
* software. If not, they may be obtained at the above URLs.
*/
#include <libc/isystem/stdio.h>
#include <libc/isystem/stdlib.h>
#include <libc/isystem/string.h>
#include <libc/isystem/limits.h>
#include "third_party/argon2/encoding.h"
#include "third_party/argon2/core.h"
/*
* Example code for a decoder and encoder of "hash strings", with Argon2
* parameters.

View file

@ -18,6 +18,7 @@
#ifndef ENCODING_H
#define ENCODING_H
#include "third_party/argon2/argon2.h"
/* clang-format off */
#define ARGON2_MAX_DECODED_LANES UINT32_C(255)
#define ARGON2_MIN_DECODED_SALT_LEN UINT32_C(8)

View file

@ -1,3 +1,10 @@
#include "third_party/argon2/argon2.h"
#include "third_party/argon2/blake2-impl.h"
#include "third_party/argon2/blake2.h"
#include "third_party/argon2/blamka-round-ref.h"
#include "third_party/argon2/core.h"
/* clang-format off */
/*
* Argon2 reference source code package - reference C implementations
*
@ -15,18 +22,6 @@
* software. If not, they may be obtained at the above URLs.
*/
#include <libc/isystem/stdint.h>
#include <libc/isystem/string.h>
#include <libc/isystem/stdlib.h>
#include "argon2.h"
#include "core.h"
#include "blamka-round-ref.h"
#include "blake2-impl.h"
#include "blake2.h"
/*
* Function fills a new memory block and optionally XORs the old block over the new one.
* @next_block must be initialized.