blob: 48db85316650739e575bb130895c3c3a85085c78 [file] [log] [blame]
Paul Bakker61b699e2014-01-22 13:35:29 +01001/**
Paul Bakkerd2c2c1c2014-04-11 15:28:52 +02002 * \file ripemd160.h
Paul Bakker61b699e2014-01-22 13:35:29 +01003 *
4 * \brief RIPE MD-160 message digest
5 *
Manuel Pégourié-Gonnarda658a402015-01-23 09:45:19 +00006 * Copyright (C) 2014-2014, ARM Limited, All Rights Reserved
Paul Bakker61b699e2014-01-22 13:35:29 +01007 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +00008 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakker61b699e2014-01-22 13:35:29 +01009 *
Paul Bakker61b699e2014-01-22 13:35:29 +010010 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 */
24#ifndef POLARSSL_RIPEMD160_H
25#define POLARSSL_RIPEMD160_H
26
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020027#if !defined(POLARSSL_CONFIG_FILE)
Paul Bakker61b699e2014-01-22 13:35:29 +010028#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020029#else
30#include POLARSSL_CONFIG_FILE
31#endif
Paul Bakker61b699e2014-01-22 13:35:29 +010032
Rich Evans00ab4702015-02-06 13:43:58 +000033#include <stddef.h>
Paul Bakker61b699e2014-01-22 13:35:29 +010034
35#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
36#include <basetsd.h>
37typedef UINT32 uint32_t;
38#else
39#include <inttypes.h>
40#endif
41
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +010042#define POLARSSL_ERR_RIPEMD160_FILE_IO_ERROR -0x007E /**< Read/write error in file. */
Paul Bakker61b699e2014-01-22 13:35:29 +010043
Paul Bakker9f4c1622014-01-22 14:14:26 +010044#if !defined(POLARSSL_RIPEMD160_ALT)
45// Regular implementation
46//
47
Paul Bakker61b699e2014-01-22 13:35:29 +010048#ifdef __cplusplus
49extern "C" {
50#endif
51
52/**
53 * \brief RIPEMD-160 context structure
54 */
55typedef struct
56{
57 uint32_t total[2]; /*!< number of bytes processed */
58 uint32_t state[5]; /*!< intermediate digest state */
59 unsigned char buffer[64]; /*!< data block being processed */
Paul Bakker61b699e2014-01-22 13:35:29 +010060}
61ripemd160_context;
62
63/**
Paul Bakker5b4af392014-06-26 12:09:34 +020064 * \brief Initialize RIPEMD-160 context
65 *
66 * \param ctx RIPEMD-160 context to be initialized
67 */
68void ripemd160_init( ripemd160_context *ctx );
69
70/**
71 * \brief Clear RIPEMD-160 context
72 *
73 * \param ctx RIPEMD-160 context to be cleared
74 */
75void ripemd160_free( ripemd160_context *ctx );
76
77/**
Paul Bakker61b699e2014-01-22 13:35:29 +010078 * \brief RIPEMD-160 context setup
79 *
80 * \param ctx context to be initialized
81 */
82void ripemd160_starts( ripemd160_context *ctx );
83
84/**
85 * \brief RIPEMD-160 process buffer
86 *
87 * \param ctx RIPEMD-160 context
88 * \param input buffer holding the data
89 * \param ilen length of the input data
90 */
91void ripemd160_update( ripemd160_context *ctx,
92 const unsigned char *input, size_t ilen );
93
94/**
95 * \brief RIPEMD-160 final digest
96 *
97 * \param ctx RIPEMD-160 context
98 * \param output RIPEMD-160 checksum result
99 */
100void ripemd160_finish( ripemd160_context *ctx, unsigned char output[20] );
101
Paul Bakker9f4c1622014-01-22 14:14:26 +0100102/* Internal use */
103void ripemd160_process( ripemd160_context *ctx, const unsigned char data[64] );
104
105#ifdef __cplusplus
106}
107#endif
108
109#else /* POLARSSL_RIPEMD160_ALT */
110#include "ripemd160.h"
111#endif /* POLARSSL_RIPEMD160_ALT */
112
113#ifdef __cplusplus
114extern "C" {
115#endif
116
Paul Bakker61b699e2014-01-22 13:35:29 +0100117/**
118 * \brief Output = RIPEMD-160( input buffer )
119 *
120 * \param input buffer holding the data
121 * \param ilen length of the input data
122 * \param output RIPEMD-160 checksum result
123 */
124void ripemd160( const unsigned char *input, size_t ilen,
125 unsigned char output[20] );
126
127#if defined(POLARSSL_FS_IO)
128/**
129 * \brief Output = RIPEMD-160( file contents )
130 *
131 * \param path input file name
132 * \param output RIPEMD-160 checksum result
133 *
134 * \return 0 if successful, or POLARSSL_ERR_RIPEMD160_FILE_IO_ERROR
135 */
136int ripemd160_file( const char *path, unsigned char output[20] );
137#endif /* POLARSSL_FS_IO */
138
139/**
Paul Bakker61b699e2014-01-22 13:35:29 +0100140 * \brief Checkup routine
141 *
142 * \return 0 if successful, or 1 if the test failed
143 */
144int ripemd160_self_test( int verbose );
145
Paul Bakker61b699e2014-01-22 13:35:29 +0100146#ifdef __cplusplus
147}
148#endif
149
150#endif /* ripemd160.h */