diff options
author | Slávek Banko <[email protected]> | 2013-07-27 16:34:45 +0200 |
---|---|---|
committer | Slávek Banko <[email protected]> | 2013-07-27 16:34:45 +0200 |
commit | d76ff81b7c1beffef0b84e570914c8f2d47834e6 (patch) | |
tree | 284b80ce7c5456fbb041f7979ac2c0baeead8902 /src/crypto.h | |
download | tork-d76ff81b7c1beffef0b84e570914c8f2d47834e6.tar.gz tork-d76ff81b7c1beffef0b84e570914c8f2d47834e6.zip |
Initial import of tork 0.33
Diffstat (limited to 'src/crypto.h')
-rw-r--r-- | src/crypto.h | 183 |
1 files changed, 183 insertions, 0 deletions
diff --git a/src/crypto.h b/src/crypto.h new file mode 100644 index 0000000..92c6094 --- /dev/null +++ b/src/crypto.h @@ -0,0 +1,183 @@ +/* $Id: crypto.h,v 1.9 2008/07/31 19:56:26 hoganrobert Exp $ */ +/* Copyright (C) 2006 - 2008 Robert Hogan * + * [email protected] * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * + * + * Most of this file is derived from Tor and Vidalia. + * + * The licences for both follow: + * + * Vidalia is distributed under the following license: + * + * Copyright (C) 2007, Matt Edman, Justin Hipple + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + * * * * + * + * Pseudorandom number generation support in this file is derived from + * Tor's crypto.[ch]. Tor is distributed under this license. + * + * Copyright (c) 2001-2004, Roger Dingledine + * Copyright (c) 2004-2007, Roger Dingledine, Nick Mathewson + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * Neither the names of the copyright owners nor the names of its + * contributors may be used to endorse or promote products derived from + * this software 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, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ****************************************************************/ + + +/** + * \file crypto.h + * + * \brief Headers for crypto.c + **/ + +#define BASE64_DIGEST_LEN 27 +#define DIGEST_LEN 20 +#define HEX_DIGEST_LEN 40 +#define SIZE_T_CEILING (sizeof(char)<<(sizeof(size_t)*8 - 1)) + +#define S2K_SPECIFIER_LEN 9 + +#include <qmap.h> +#include <qstring.h> + +typedef struct crypto_digest_env_t crypto_digest_env_t; + + +int read_all(int fd, char *buf, size_t count, int isSocket); +int base64_decode(char *dest, size_t destlen, const char *src, size_t srclen); +int digest_from_base64(char *digest, const char *d64); +void base16_encode(char *dest, size_t destlen, const char *src, size_t srclen); +int digest_to_base64(char *d64, const char *digest); +int base64_encode(char *dest, size_t destlen, const char *src, size_t srclen); +int base16_decode(char *dest, size_t destlen, const char *src, size_t srclen); + +QString getFPDigestFromFP(const QString &fp); +QString getNickNameFromFPDigest(const QString &fpdigest); +QString getNickNameFromFP(const QString &fp); +QString getFPFromNickName(const QString &nickname); +QString getFPFromFPDigest(const QString &fp); +void storeServer(const QString &server,const QString &fp_identity); +void clearServers(); +QString fp_identity(const QString &server); +QString server(const QString &fp_identity); +QString hashPassword(const char* secret); + +QString crypto_rand_string(int len); + +/* random numbers */ +int crypto_seed_rng(void); +int crypto_rand(char *to, size_t n); +int crypto_rand_int(unsigned int max); + + + +/* +cdecode.h - c header for a base64 decoding algorithm + +This is part of the libb64 project, and has been placed in the public domain. +For details, see http://sourceforge.net/projects/libb64 +*/ + + +typedef enum +{ + step_a, step_b, step_c, step_d +} base64_decodestep; + +typedef struct +{ + base64_decodestep step; + char plainchar; +} base64_decodestate; + +void base64_init_decodestate(base64_decodestate* state_in); + +int base64_decode_value(char value_in); + +int base64_decode_block(const char* code_in, const int length_in, char* plaintext_out, base64_decodestate* state_in); + + +/* +cencode.h - c header for a base64 encoding algorithm + +This is part of the libb64 project, and has been placed in the public domain. +For details, see http://sourceforge.net/projects/libb64 +*/ + + +typedef enum +{ + step_A, step_B, step_C +} base64_encodestep; + +typedef struct +{ + base64_encodestep step; + char result; + int stepcount; +} base64_encodestate; + +void base64_init_encodestate(base64_encodestate* state_in); + +char base64_encode_value(char value_in); + +int base64_encode_block(const char* plaintext_in, int length_in, char* code_out, base64_encodestate* state_in); + +int base64_encode_blockend(char* code_out, base64_encodestate* state_in); + + + |