Apache Portable Runtime
apr_sha1.h
Go to the documentation of this file.
00001 /* Licensed to the Apache Software Foundation (ASF) under one or more
00002  * contributor license agreements.  See the NOTICE file distributed with
00003  * this work for additional information regarding copyright ownership.
00004  * The ASF licenses this file to You under the Apache License, Version 2.0
00005  * (the "License"); you may not use this file except in compliance with
00006  * the License.  You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 /* NIST Secure Hash Algorithm
00017  *      heavily modified by Uwe Hollerbach uh@alumni.caltech edu
00018  *      from Peter C. Gutmann's implementation as found in
00019  *      Applied Cryptography by Bruce Schneier
00020  *      This code is hereby placed in the public domain
00021  */
00022 
00023 #ifndef APR_SHA1_H
00024 #define APR_SHA1_H
00025 
00026 #include "apu.h"
00027 #include "apr_general.h"
00028 
00029 #ifdef __cplusplus
00030 extern "C" {
00031 #endif
00032 
00033 /**
00034  * @file apr_sha1.h
00035  * @brief APR-UTIL SHA1 library
00036  */
00037 
00038 /** size of the SHA1 DIGEST */
00039 #define APR_SHA1_DIGESTSIZE 20
00040 
00041 /**
00042  * Define the Magic String prefix that identifies a password as being
00043  * hashed using our algorithm.
00044  */
00045 #define APR_SHA1PW_ID "{SHA}"
00046 
00047 /** length of the SHA Password */
00048 #define APR_SHA1PW_IDLEN 5
00049 
00050 /** @see apr_sha1_ctx_t */
00051 typedef struct apr_sha1_ctx_t apr_sha1_ctx_t;
00052 
00053 /** 
00054  * SHA1 context structure
00055  */
00056 struct apr_sha1_ctx_t {
00057     /** message digest */
00058     apr_uint32_t digest[5];
00059     /** 64-bit bit counts */
00060     apr_uint32_t count_lo, count_hi;
00061     /** SHA data buffer */
00062     apr_uint32_t data[16];
00063     /** unprocessed amount in data */
00064     int local;
00065 };
00066 
00067 /**
00068  * Provide a means to SHA1 crypt/encode a plaintext password in a way which
00069  * makes password file compatible with those commonly use in netscape web
00070  * and ldap installations.
00071  * @param clear The plaintext password
00072  * @param len The length of the plaintext password
00073  * @param out The encrypted/encoded password
00074  * @note SHA1 support is useful for migration purposes, but is less
00075  *     secure than Apache's password format, since Apache's (MD5)
00076  *     password format uses a random eight character salt to generate
00077  *     one of many possible hashes for the same password.  Netscape
00078  *     uses plain SHA1 without a salt, so the same password
00079  *     will always generate the same hash, making it easier
00080  *     to break since the search space is smaller.
00081  */
00082 APR_DECLARE(void) apr_sha1_base64(const char *clear, int len, char *out);
00083 
00084 /**
00085  * Initialize the SHA digest
00086  * @param context The SHA context to initialize
00087  */
00088 APR_DECLARE(void) apr_sha1_init(apr_sha1_ctx_t *context);
00089 
00090 /**
00091  * Update the SHA digest
00092  * @param context The SHA1 context to update
00093  * @param input The buffer to add to the SHA digest
00094  * @param inputLen The length of the input buffer
00095  */
00096 APR_DECLARE(void) apr_sha1_update(apr_sha1_ctx_t *context, const char *input,
00097                                 unsigned int inputLen);
00098 
00099 /**
00100  * Update the SHA digest with binary data
00101  * @param context The SHA1 context to update
00102  * @param input The buffer to add to the SHA digest
00103  * @param inputLen The length of the input buffer
00104  */
00105 APR_DECLARE(void) apr_sha1_update_binary(apr_sha1_ctx_t *context,
00106                                        const unsigned char *input,
00107                                        unsigned int inputLen);
00108 
00109 /**
00110  * Finish computing the SHA digest
00111  * @param digest the output buffer in which to store the digest
00112  * @param context The context to finalize
00113  */
00114 APR_DECLARE(void) apr_sha1_final(unsigned char digest[APR_SHA1_DIGESTSIZE],
00115                                apr_sha1_ctx_t *context);
00116 
00117 #ifdef __cplusplus
00118 }
00119 #endif
00120 
00121 #endif  /* APR_SHA1_H */
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines