1253734Speter/* Licensed to the Apache Software Foundation (ASF) under one or more 2253734Speter * contributor license agreements. See the NOTICE file distributed with 3253734Speter * this work for additional information regarding copyright ownership. 4253734Speter * The ASF licenses this file to You under the Apache License, Version 2.0 5253734Speter * (the "License"); you may not use this file except in compliance with 6253734Speter * the License. You may obtain a copy of the License at 7253734Speter * 8253734Speter * http://www.apache.org/licenses/LICENSE-2.0 9253734Speter * 10253734Speter * Unless required by applicable law or agreed to in writing, software 11253734Speter * distributed under the License is distributed on an "AS IS" BASIS, 12253734Speter * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13253734Speter * See the License for the specific language governing permissions and 14253734Speter * limitations under the License. 15253734Speter */ 16253734Speter 17251875Speter#include <apr.h> 18251875Speter#include <apr_random.h> 19251875Speter#include <apr_pools.h> 20251875Speter#include "sha2.h" 21251875Speter 22251875Speterstatic void sha256_init(apr_crypto_hash_t *h) 23253734Speter{ 24251875Speter apr__SHA256_Init(h->data); 25253734Speter} 26251875Speter 27251875Speterstatic void sha256_add(apr_crypto_hash_t *h,const void *data, 28253734Speter apr_size_t bytes) 29253734Speter{ 30251875Speter apr__SHA256_Update(h->data,data,bytes); 31253734Speter} 32251875Speter 33251875Speterstatic void sha256_finish(apr_crypto_hash_t *h,unsigned char *result) 34253734Speter{ 35251875Speter apr__SHA256_Final(result,h->data); 36253734Speter} 37251875Speter 38251875SpeterAPR_DECLARE(apr_crypto_hash_t *) apr_crypto_sha256_new(apr_pool_t *p) 39253734Speter{ 40251875Speter apr_crypto_hash_t *h=apr_palloc(p,sizeof *h); 41251875Speter 42251875Speter h->data=apr_palloc(p,sizeof(SHA256_CTX)); 43251875Speter h->init=sha256_init; 44251875Speter h->add=sha256_add; 45251875Speter h->finish=sha256_finish; 46251875Speter h->size=256/8; 47251875Speter 48251875Speter return h; 49253734Speter} 50