From: nishi Date: Sat, 20 Apr 2024 00:47:52 +0000 (+0000) Subject: add crypto X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=f3907eab6d055758b83d8530edbf2e85d469d17f;p=mandshurica.git add crypto git-svn-id: file:///raid/svn-main/nishi-mandshurica/trunk@46 f982e544-4a7d-3444-ad1a-fde59a2a69f1 --- diff --git a/Mandshurica/Makefile b/Mandshurica/Makefile index 3e3236e..5848491 100644 --- a/Mandshurica/Makefile +++ b/Mandshurica/Makefile @@ -2,7 +2,7 @@ EXTRA_CFLAGS = -pthread EXTRA_LDFLAGS = -EXTRA_LIBS = -pthread +EXTRA_LIBS = -pthread -lcrypto .PHONY: all clean @@ -12,7 +12,7 @@ endif all: ./mandshurica -./mandshurica: ./main.o ./log.o ./config.o ./util.o ./template.o ./file.o ./db.o +./mandshurica: ./main.o ./log.o ./config.o ./util.o ./template.o ./file.o ./db.o ./crypto.o $(CC) $(LDFLAGS) $(EXTRA_LDFLAGS) -o $@ $^ $(LIBS) $(EXTRA_LIBS) ./main.o: ./main.c ./mandshurica.h diff --git a/Mandshurica/crypto.c b/Mandshurica/crypto.c new file mode 100644 index 0000000..8a6a092 --- /dev/null +++ b/Mandshurica/crypto.c @@ -0,0 +1,57 @@ +/* $Id$ */ +/* --- START LICENSE --- */ +/* -------------------------------------------------------------------------- */ +/* Mandshurica - Build Automation */ +/* -------------------------------------------------------------------------- */ +/* Copyright (c) 2024 Nishi. */ +/* Redistribution and use in source and binary forms, with or without modific */ +/* ation, are permitted provided that the following conditions are met: */ +/* 1. Redistributions of source code must retain the above copyright noti */ +/* ce, this list of conditions and the following disclaimer. */ +/* 2. Redistributions in binary form must reproduce the above copyright n */ +/* otice, this list of conditions and the following disclaimer in the documen */ +/* tation and/or other materials provided with the distribution. */ +/* 3. Neither the name of the copyright holder nor the names of its contr */ +/* ibutors may be used to endorse or promote products derived from this softw */ +/* are without specific prior written permission. */ +/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS */ +/* " AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, TH */ +/* E IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPO */ +/* SE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS */ +/* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CON */ +/* SEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITU */ +/* TE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPT */ +/* ION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, S */ +/* TRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN AN */ +/* Y WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY */ +/* OF SUCH DAMAGE. */ +/* -------------------------------------------------------------------------- */ +/* --- END LICENSE --- */ + +#include "ms_crypto.h" + +#include + +#include + +char num2hex(int num) { + if(num >= 0 && num <= 9) return num + '0'; + if(num >= 10 && num <= 15) return num - 10 + 'a'; +} + +char* mandshurica_sha512(const char* pwd) { + SHA512_CTX ctx; + unsigned char buffer[64]; + SHA512_Init(&ctx); + SHA512_Update(&ctx, pwd, strlen(pwd)); + SHA512_Final(buffer, &ctx); + char* buf = malloc(129); + int i; + for(i = 0; i < 64; i++) { + buf[i * 2 + 0] = num2hex((buffer[i] & 0xf0) >> 4); + buf[i * 2 + 1] = num2hex((buffer[i] & 0x0f) >> 0); + } + buf[128] = 0; + printf("%s\n", buf); + return buf; +} diff --git a/Mandshurica/ms_crypto.h b/Mandshurica/ms_crypto.h new file mode 100644 index 0000000..1bfa825 --- /dev/null +++ b/Mandshurica/ms_crypto.h @@ -0,0 +1,36 @@ +/* $Id$ */ +/* --- START LICENSE --- */ +/* -------------------------------------------------------------------------- */ +/* Mandshurica - Build Automation */ +/* -------------------------------------------------------------------------- */ +/* Copyright (c) 2024 Nishi. */ +/* Redistribution and use in source and binary forms, with or without modific */ +/* ation, are permitted provided that the following conditions are met: */ +/* 1. Redistributions of source code must retain the above copyright noti */ +/* ce, this list of conditions and the following disclaimer. */ +/* 2. Redistributions in binary form must reproduce the above copyright n */ +/* otice, this list of conditions and the following disclaimer in the documen */ +/* tation and/or other materials provided with the distribution. */ +/* 3. Neither the name of the copyright holder nor the names of its contr */ +/* ibutors may be used to endorse or promote products derived from this softw */ +/* are without specific prior written permission. */ +/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS */ +/* " AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, TH */ +/* E IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPO */ +/* SE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS */ +/* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CON */ +/* SEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITU */ +/* TE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPT */ +/* ION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, S */ +/* TRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN AN */ +/* Y WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY */ +/* OF SUCH DAMAGE. */ +/* -------------------------------------------------------------------------- */ +/* --- END LICENSE --- */ + +#ifndef __MANDSHURICA_MS_CRYPTO_H__ +#define __MANDSHURICA_MS_CRYPTO_H__ + +char* mandshurica_sha512(const char* pwd); + +#endif diff --git a/mkpasswd.pl b/mkpasswd.pl index 0722128..2e662f4 100755 --- a/mkpasswd.pl +++ b/mkpasswd.pl @@ -13,12 +13,12 @@ print STDERR "Password: "; Term::ReadKey::ReadMode("noecho"); -my $password = Term::ReadKey::ReadLine(0); +chomp(my $password = Term::ReadKey::ReadLine(0)); print STDERR "\n"; print STDERR "Verify Password: "; -my $verify = Term::ReadKey::ReadLine(0); +chomp(my $verify = Term::ReadKey::ReadLine(0)); print STDERR "\n";