Apache Portable Runtime
sha2.h
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 /*
00017  * FILE:        sha2.h
00018  * AUTHOR:      Aaron D. Gifford <me@aarongifford.com>
00019  * 
00020  * A licence was granted to the ASF by Aaron on 4 November 2003.
00021  */
00022 
00023 #ifndef __SHA2_H__
00024 #define __SHA2_H__
00025 
00026 #ifdef __cplusplus
00027 extern "C" {
00028 #endif
00029 
00030 #include "apr.h"
00031 
00032 /*** SHA-256/384/512 Various Length Definitions ***********************/
00033 #define SHA256_BLOCK_LENGTH             64
00034 #define SHA256_DIGEST_LENGTH            32
00035 #define SHA256_DIGEST_STRING_LENGTH     (SHA256_DIGEST_LENGTH * 2 + 1)
00036 #define SHA384_BLOCK_LENGTH             128
00037 #define SHA384_DIGEST_LENGTH            48
00038 #define SHA384_DIGEST_STRING_LENGTH     (SHA384_DIGEST_LENGTH * 2 + 1)
00039 #define SHA512_BLOCK_LENGTH             128
00040 #define SHA512_DIGEST_LENGTH            64
00041 #define SHA512_DIGEST_STRING_LENGTH     (SHA512_DIGEST_LENGTH * 2 + 1)
00042 
00043 
00044 /*** SHA-256/384/512 Context Structures *******************************/
00045 typedef struct _SHA256_CTX {
00046         apr_uint32_t    state[8];
00047         apr_uint64_t    bitcount;
00048         apr_byte_t      buffer[SHA256_BLOCK_LENGTH];
00049 } SHA256_CTX;
00050 typedef struct _SHA512_CTX {
00051         apr_uint64_t    state[8];
00052         apr_uint64_t    bitcount[2];
00053         apr_byte_t      buffer[SHA512_BLOCK_LENGTH];
00054 } SHA512_CTX;
00055 
00056 typedef SHA512_CTX SHA384_CTX;
00057 
00058 
00059 /*** SHA-256/384/512 Function Prototypes ******************************/
00060 void apr__SHA256_Init(SHA256_CTX *);
00061 void apr__SHA256_Update(SHA256_CTX *, const apr_byte_t *, size_t);
00062 void apr__SHA256_Final(apr_byte_t [SHA256_DIGEST_LENGTH], SHA256_CTX *);
00063 char* apr__SHA256_End(SHA256_CTX *, char [SHA256_DIGEST_STRING_LENGTH]);
00064 char* apr__SHA256_Data(const apr_byte_t *, size_t,
00065                   char [SHA256_DIGEST_STRING_LENGTH]);
00066 
00067 void apr__SHA384_Init(SHA384_CTX *);
00068 void apr__SHA384_Update(SHA384_CTX *, const apr_byte_t *, size_t);
00069 void apr__SHA384_Final(apr_byte_t [SHA384_DIGEST_LENGTH], SHA384_CTX *);
00070 char* apr__SHA384_End(SHA384_CTX *, char [SHA384_DIGEST_STRING_LENGTH]);
00071 char* apr__SHA384_Data(const apr_byte_t *, size_t,
00072                   char [SHA384_DIGEST_STRING_LENGTH]);
00073 
00074 void apr__SHA512_Init(SHA512_CTX *);
00075 void apr__SHA512_Update(SHA512_CTX *, const apr_byte_t *, size_t);
00076 void apr__SHA512_Final(apr_byte_t [SHA512_DIGEST_LENGTH], SHA512_CTX *);
00077 char* apr__SHA512_End(SHA512_CTX *, char [SHA512_DIGEST_STRING_LENGTH]);
00078 char* apr__SHA512_Data(const apr_byte_t *, size_t,
00079                   char [SHA512_DIGEST_STRING_LENGTH]);
00080 
00081 #ifdef  __cplusplus
00082 }
00083 #endif /* __cplusplus */
00084 
00085 #endif /* __SHA2_H__ */
00086 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines