"Fossies" - the Fresh Open Source Software Archive

Member "s-nail-14.9.19/include/mx/cred-md5.h" (26 Apr 2020, 3904 Bytes) of package /linux/misc/s-nail-14.9.19.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "cred-md5.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 14.9.18_vs_14.9.19.

    1 /*@ S-nail - a mail user agent derived from Berkeley Mail.
    2  *@ MD5 message digest related.
    3  *
    4  * Copyright (c) 2014 - 2020 Steffen (Daode) Nurpmeso <steffen@sdaoden.eu>.
    5  * SPDX-License-Identifier: ISC
    6  *
    7  * Permission to use, copy, modify, and/or distribute this software for any
    8  * purpose with or without fee is hereby granted, provided that the above
    9  * copyright notice and this permission notice appear in all copies.
   10  *
   11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
   12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
   13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
   14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
   15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
   16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
   17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
   18  */
   19 /* MD5.H - header file for MD5C.C from RFC 1321 is */
   20 /* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
   21 rights reserved.
   22 
   23 License to copy and use this software is granted provided that it
   24 is identified as the "RSA Data Security, Inc. MD5 Message-Digest
   25 Algorithm" in all material mentioning or referencing this software
   26 or this function.
   27 
   28 License is also granted to make and use derivative works provided
   29 that such works are identified as "derived from the RSA Data
   30 Security, Inc. MD5 Message-Digest Algorithm" in all material
   31 mentioning or referencing the derived work.
   32 
   33 RSA Data Security, Inc. makes no representations concerning either
   34 the merchantability of this software or the suitability of this
   35 software for any particular purpose. It is provided "as is"
   36 without express or implied warranty of any kind.
   37 
   38 These notices must be retained in any copies of any part of this
   39 documentation and/or software.
   40  */
   41 #ifndef mx_CRED_MD5_H
   42 #define mx_CRED_MD5_H
   43 
   44 #include <mx/nail.h>
   45 #ifdef mx_HAVE_MD5
   46 #ifdef mx_XTLS_HAVE_MD5
   47 # include <openssl/md5.h>
   48 #endif
   49 
   50 #define mx_HEADER
   51 #include <su/code-in.h>
   52 
   53 /* */
   54 #define mx_MD5_DIGEST_SIZE 16u
   55 
   56 /* */
   57 #define mx_MD5_TOHEX_SIZE 32u
   58 
   59 /* MD5 (RFC 1321) related facilities */
   60 #ifdef mx_XTLS_HAVE_MD5
   61 # define mx_md5_t MD5_CTX
   62 # define mx_md5_init MD5_Init
   63 # define mx_md5_update MD5_Update
   64 # define mx_md5_final MD5_Final
   65 #else
   66 /* RFC 1321, MD5.H: */
   67 /*
   68  * This version of MD5 has been changed such that any unsigned type with
   69  * at least 32 bits is acceptable. This is important e.g. for Cray vector
   70  * machines which provide only 64-bit integers.
   71  */
   72 typedef unsigned long mx_md5_type;
   73 
   74 typedef struct{
   75    mx_md5_type state[4]; /* state (ABCD) */
   76    mx_md5_type count[2]; /* number of bits, modulo 2^64 (lsb first) */
   77    unsigned char buffer[64]; /* input buffer */
   78 } mx_md5_t;
   79 
   80 EXPORT void mx_md5_init(mx_md5_t *);
   81 EXPORT void mx_md5_update(mx_md5_t *, unsigned char *, unsigned int);
   82 EXPORT void mx_md5_final(unsigned char[mx_MD5_DIGEST_SIZE], mx_md5_t *);
   83 #endif /* mx_XTLS_HAVE_MD5 */
   84 
   85 /* Store the MD5 checksum as a hexadecimal string in *hex*, *not* terminated,
   86  * using lowercase ASCII letters as defined in RFC 2195 */
   87 EXPORT char *mx_md5_tohex(char hex[mx_MD5_TOHEX_SIZE], void const *vp);
   88 
   89 /* CRAM-MD5 encode the *user* / *pass* / *b64* combo; NULL on overflow error */
   90 EXPORT char *mx_md5_cram_string(struct str const *user, struct str const *pass,
   91       char const *b64);
   92 
   93 /* RFC 2104: HMAC: Keyed-Hashing for Message Authentication.
   94  * unsigned char *text: pointer to data stream
   95  * int text_len       : length of data stream
   96  * unsigned char *key : pointer to authentication key
   97  * int key_len        : length of authentication key
   98  * caddr_t digest     : caller digest to be filled in */
   99 EXPORT void mx_md5_hmac(unsigned char *text, int text_len, unsigned char *key,
  100       int key_len, void *digest);
  101 
  102 #include <su/code-ou.h>
  103 #endif /* mx_HAVE_MD5 */
  104 #endif /* mx_CRED_MD5_H */
  105 /* s-it-mode */