1251876Speter/* Licensed to the Apache Software Foundation (ASF) under one or more
2251876Speter * contributor license agreements.  See the NOTICE file distributed with
3251876Speter * this work for additional information regarding copyright ownership.
4251876Speter * The ASF licenses this file to You under the Apache License, Version 2.0
5251876Speter * (the "License"); you may not use this file except in compliance with
6251876Speter * the License.  You may obtain a copy of the License at
7251876Speter *
8251876Speter *     http://www.apache.org/licenses/LICENSE-2.0
9251876Speter *
10251876Speter * Unless required by applicable law or agreed to in writing, software
11251876Speter * distributed under the License is distributed on an "AS IS" BASIS,
12251876Speter * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13251876Speter * See the License for the specific language governing permissions and
14251876Speter * limitations under the License.
15251876Speter */
16251876Speter/* NIST Secure Hash Algorithm
17251876Speter * 	heavily modified by Uwe Hollerbach uh@alumni.caltech edu
18251876Speter * 	from Peter C. Gutmann's implementation as found in
19251876Speter * 	Applied Cryptography by Bruce Schneier
20251876Speter * 	This code is hereby placed in the public domain
21251876Speter */
22251876Speter
23251876Speter#ifndef APR_SHA1_H
24251876Speter#define APR_SHA1_H
25251876Speter
26251876Speter#include "apu.h"
27251876Speter#include "apr_general.h"
28251876Speter
29251876Speter#ifdef __cplusplus
30251876Speterextern "C" {
31251876Speter#endif
32251876Speter
33251876Speter/**
34251876Speter * @file apr_sha1.h
35251876Speter * @brief APR-UTIL SHA1 library
36251876Speter */
37251876Speter
38251876Speter/** size of the SHA1 DIGEST */
39251876Speter#define APR_SHA1_DIGESTSIZE 20
40251876Speter
41251876Speter/**
42251876Speter * Define the Magic String prefix that identifies a password as being
43251876Speter * hashed using our algorithm.
44251876Speter */
45251876Speter#define APR_SHA1PW_ID "{SHA}"
46251876Speter
47251876Speter/** length of the SHA Password */
48251876Speter#define APR_SHA1PW_IDLEN 5
49251876Speter
50251876Speter/** @see apr_sha1_ctx_t */
51251876Spetertypedef struct apr_sha1_ctx_t apr_sha1_ctx_t;
52251876Speter
53251876Speter/**
54251876Speter * SHA1 context structure
55251876Speter */
56251876Speterstruct apr_sha1_ctx_t {
57251876Speter    /** message digest */
58251876Speter    apr_uint32_t digest[5];
59251876Speter    /** 64-bit bit counts */
60251876Speter    apr_uint32_t count_lo, count_hi;
61251876Speter    /** SHA data buffer */
62251876Speter    apr_uint32_t data[16];
63251876Speter    /** unprocessed amount in data */
64251876Speter    int local;
65251876Speter};
66251876Speter
67251876Speter/**
68251876Speter * Provide a means to SHA1 crypt/encode a plaintext password in a way which
69251876Speter * makes password file compatible with those commonly use in netscape web
70251876Speter * and ldap installations.
71251876Speter * @param clear The plaintext password
72251876Speter * @param len The length of the plaintext password
73251876Speter * @param out The encrypted/encoded password
74251876Speter * @note SHA1 support is useful for migration purposes, but is less
75251876Speter *     secure than Apache's password format, since Apache's (MD5)
76251876Speter *     password format uses a random eight character salt to generate
77251876Speter *     one of many possible hashes for the same password.  Netscape
78251876Speter *     uses plain SHA1 without a salt, so the same password
79251876Speter *     will always generate the same hash, making it easier
80251876Speter *     to break since the search space is smaller.
81251876Speter */
82251876SpeterAPU_DECLARE(void) apr_sha1_base64(const char *clear, int len, char *out);
83251876Speter
84251876Speter/**
85251876Speter * Initialize the SHA digest
86251876Speter * @param context The SHA context to initialize
87251876Speter */
88251876SpeterAPU_DECLARE(void) apr_sha1_init(apr_sha1_ctx_t *context);
89251876Speter
90251876Speter/**
91251876Speter * Update the SHA digest
92251876Speter * @param context The SHA1 context to update
93251876Speter * @param input The buffer to add to the SHA digest
94251876Speter * @param inputLen The length of the input buffer
95251876Speter */
96251876SpeterAPU_DECLARE(void) apr_sha1_update(apr_sha1_ctx_t *context, const char *input,
97251876Speter                                unsigned int inputLen);
98251876Speter
99251876Speter/**
100251876Speter * Update the SHA digest with binary data
101251876Speter * @param context The SHA1 context to update
102251876Speter * @param input The buffer to add to the SHA digest
103251876Speter * @param inputLen The length of the input buffer
104251876Speter */
105251876SpeterAPU_DECLARE(void) apr_sha1_update_binary(apr_sha1_ctx_t *context,
106251876Speter                                       const unsigned char *input,
107251876Speter                                       unsigned int inputLen);
108251876Speter
109251876Speter/**
110251876Speter * Finish computing the SHA digest
111251876Speter * @param digest the output buffer in which to store the digest
112251876Speter * @param context The context to finalize
113251876Speter */
114251876SpeterAPU_DECLARE(void) apr_sha1_final(unsigned char digest[APR_SHA1_DIGESTSIZE],
115251876Speter                               apr_sha1_ctx_t *context);
116251876Speter
117251876Speter#ifdef __cplusplus
118251876Speter}
119251876Speter#endif
120251876Speter
121251876Speter#endif	/* APR_SHA1_H */
122