mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 20:15:17 +00:00
Everywhere: Remove LibCrypt
This was totally unused.
This commit is contained in:
parent
f2fd8fc928
commit
5b4d071daa
Notes:
sideshowbarker
2024-07-17 07:48:42 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/LadybirdBrowser/ladybird/commit/5b4d071daa Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/37
3 changed files with 0 additions and 114 deletions
|
@ -1,16 +0,0 @@
|
|||
|
||||
# HACK ALERT!
|
||||
# To avoid a circular dependency chain with LibCrypt --> LibCrypto --> LibCore --> LibCrypt
|
||||
# We include the SHA2 implementation from LibCrypto here manually
|
||||
add_library(LibCryptSHA2 OBJECT ../LibCrypto/Hash/SHA2.cpp)
|
||||
add_dependencies(LibCryptSHA2 install_libc_headers)
|
||||
set_target_properties(LibCryptSHA2 PROPERTIES CXX_VISIBILITY_PRESET hidden)
|
||||
set_target_properties(LibCryptSHA2 PROPERTIES VISIBILITY_INLINES_HIDDEN ON)
|
||||
|
||||
set(SOURCES
|
||||
crypt.cpp
|
||||
)
|
||||
|
||||
serenity_lib(LibCrypt crypt)
|
||||
serenity_install_headers("")
|
||||
target_link_libraries(LibCrypt PRIVATE LibCryptSHA2)
|
|
@ -1,70 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Peter Elliott <pelliott@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/Base64.h>
|
||||
#include <AK/Types.h>
|
||||
#include <LibCrypto/Hash/SHA2.h>
|
||||
#include <crypt.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
static struct crypt_data crypt_data;
|
||||
|
||||
char* crypt(char const* key, char const* salt)
|
||||
{
|
||||
crypt_data.initialized = true;
|
||||
return crypt_r(key, salt, &crypt_data);
|
||||
}
|
||||
|
||||
static constexpr size_t crypt_salt_max = 16;
|
||||
|
||||
char* crypt_r(char const* key, char const* salt, struct crypt_data* data)
|
||||
{
|
||||
if (!data->initialized) {
|
||||
errno = EINVAL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// We only support SHA-256 at the moment
|
||||
if (salt[0] != '$' || salt[1] != '5') {
|
||||
errno = EINVAL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
char const* salt_value = salt + 3;
|
||||
size_t salt_len = min(strcspn(salt_value, "$"), crypt_salt_max);
|
||||
size_t header_len = salt_len + 3;
|
||||
|
||||
bool fits = ByteString(salt, header_len).copy_characters_to_buffer(data->result, sizeof(data->result));
|
||||
if (!fits) {
|
||||
errno = EINVAL;
|
||||
return nullptr;
|
||||
}
|
||||
data->result[header_len] = '$';
|
||||
|
||||
Crypto::Hash::SHA256 sha;
|
||||
sha.update(StringView { key, strlen(key) });
|
||||
sha.update(reinterpret_cast<u8 const*>(salt_value), salt_len);
|
||||
|
||||
auto digest = sha.digest();
|
||||
auto string_or_error = encode_base64({ digest.immutable_data(), digest.data_length() });
|
||||
if (string_or_error.is_error()) {
|
||||
errno = ENOMEM;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto string = string_or_error.value().bytes_as_string_view();
|
||||
fits = string.copy_characters_to_buffer(data->result + header_len + 1, sizeof(data->result) - header_len - 1);
|
||||
if (!fits) {
|
||||
errno = EINVAL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return data->result;
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
/* standard symbolic constants and types
|
||||
*
|
||||
* values from POSIX standard unix specification
|
||||
*
|
||||
* https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/unistd.h.html
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
struct crypt_data {
|
||||
int initialized;
|
||||
char result[65];
|
||||
};
|
||||
|
||||
char* crypt(char const* key, char const* salt);
|
||||
char* crypt_r(char const* key, char const* salt, struct crypt_data* data);
|
||||
|
||||
__END_DECLS
|
Loading…
Add table
Reference in a new issue