Update Argon2 for style

- Make sure notice licenses are embedded
- Remove copyright and docs from headers
This commit is contained in:
Justine Tunney 2022-03-21 07:25:48 -07:00
parent f78f2fcac3
commit 4881ae7527
11 changed files with 613 additions and 711 deletions

View file

@ -1,26 +1,31 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=4 sts=4 sw=4 fenc=utf-8 :vi
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 │
*/
#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
*
* 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.
*/
asm(".ident\t\"\\n\\n\
argon2 (CC0 or Apache2)\\n\
Copyright 2016 Daniel Dinu, Dmitry Khovratovich\\n\
Copyright 2016 Jean-Philippe Aumasson, Samuel Neves\"");
/* clang-format off */
/*
* Example code for a decoder and encoder of "hash strings", with Argon2
@ -255,6 +260,18 @@ static const char *decode_decimal(const char *str, unsigned long *v) {
* when it is fed into decode_string.
*/
/**
* Decodes an Argon2 hash string into the provided structure 'ctx'.
* The only fields that must be set prior to this call are ctx.saltlen and
* ctx.outlen (which must be the maximal salt and out length values that are
* allowed), ctx.salt and ctx.out (which must be buffers of the specified
* length), and ctx.pwd and ctx.pwdlen which must hold a valid password.
*
* Invalid input string causes an error. On success, the ctx is valid and all
* fields have been initialized.
*
* @return value is ARGON2_OK on success, other ARGON2_ codes on error
*/
int decode_string(argon2_context *ctx, const char *str, argon2_type type) {
/* check for prefix */
@ -370,6 +387,14 @@ int decode_string(argon2_context *ctx, const char *str, argon2_type type) {
#undef BIN
}
/**
* Encodes an Argon2 hash string into the provided buffer. 'dst_len'
* contains the size, in characters, of the 'dst' buffer; if 'dst_len'
* is less than the number of required characters (including the
* terminating 0), then this function returns ARGON2_ENCODING_ERROR.
*
* @return on success, ARGON2_OK is returned
*/
int encode_string(char *dst, size_t dst_len, argon2_context *ctx,
argon2_type type) {
#define SS(str) \
@ -437,9 +462,9 @@ int encode_string(char *dst, size_t dst_len, argon2_context *ctx,
#undef SB
}
/** Returns length of the encoded byte stream with length len */
size_t b64len(uint32_t len) {
size_t olen = ((size_t)len / 3) << 2;
switch (len % 3) {
case 2:
olen++;
@ -448,10 +473,10 @@ size_t b64len(uint32_t len) {
olen += 2;
break;
}
return olen;
}
/** Returns length of the encoded number num */
size_t numlen(uint32_t num) {
size_t len = 1;
while (num >= 10) {