Marco Zecchini
/
Example_RTOS
Rtos API example
mbed-os/features/mbedtls/src/md2.c@0:9fca2b23d0ba, 2019-02-23 (annotated)
- Committer:
- marcozecchini
- Date:
- Sat Feb 23 12:13:36 2019 +0000
- Revision:
- 0:9fca2b23d0ba
final commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
marcozecchini | 0:9fca2b23d0ba | 1 | /* |
marcozecchini | 0:9fca2b23d0ba | 2 | * RFC 1115/1319 compliant MD2 implementation |
marcozecchini | 0:9fca2b23d0ba | 3 | * |
marcozecchini | 0:9fca2b23d0ba | 4 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved |
marcozecchini | 0:9fca2b23d0ba | 5 | * SPDX-License-Identifier: Apache-2.0 |
marcozecchini | 0:9fca2b23d0ba | 6 | * |
marcozecchini | 0:9fca2b23d0ba | 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
marcozecchini | 0:9fca2b23d0ba | 8 | * not use this file except in compliance with the License. |
marcozecchini | 0:9fca2b23d0ba | 9 | * You may obtain a copy of the License at |
marcozecchini | 0:9fca2b23d0ba | 10 | * |
marcozecchini | 0:9fca2b23d0ba | 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
marcozecchini | 0:9fca2b23d0ba | 12 | * |
marcozecchini | 0:9fca2b23d0ba | 13 | * Unless required by applicable law or agreed to in writing, software |
marcozecchini | 0:9fca2b23d0ba | 14 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
marcozecchini | 0:9fca2b23d0ba | 15 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
marcozecchini | 0:9fca2b23d0ba | 16 | * See the License for the specific language governing permissions and |
marcozecchini | 0:9fca2b23d0ba | 17 | * limitations under the License. |
marcozecchini | 0:9fca2b23d0ba | 18 | * |
marcozecchini | 0:9fca2b23d0ba | 19 | * This file is part of mbed TLS (https://tls.mbed.org) |
marcozecchini | 0:9fca2b23d0ba | 20 | */ |
marcozecchini | 0:9fca2b23d0ba | 21 | /* |
marcozecchini | 0:9fca2b23d0ba | 22 | * The MD2 algorithm was designed by Ron Rivest in 1989. |
marcozecchini | 0:9fca2b23d0ba | 23 | * |
marcozecchini | 0:9fca2b23d0ba | 24 | * http://www.ietf.org/rfc/rfc1115.txt |
marcozecchini | 0:9fca2b23d0ba | 25 | * http://www.ietf.org/rfc/rfc1319.txt |
marcozecchini | 0:9fca2b23d0ba | 26 | */ |
marcozecchini | 0:9fca2b23d0ba | 27 | |
marcozecchini | 0:9fca2b23d0ba | 28 | #if !defined(MBEDTLS_CONFIG_FILE) |
marcozecchini | 0:9fca2b23d0ba | 29 | #include "mbedtls/config.h" |
marcozecchini | 0:9fca2b23d0ba | 30 | #else |
marcozecchini | 0:9fca2b23d0ba | 31 | #include MBEDTLS_CONFIG_FILE |
marcozecchini | 0:9fca2b23d0ba | 32 | #endif |
marcozecchini | 0:9fca2b23d0ba | 33 | |
marcozecchini | 0:9fca2b23d0ba | 34 | #if defined(MBEDTLS_MD2_C) |
marcozecchini | 0:9fca2b23d0ba | 35 | |
marcozecchini | 0:9fca2b23d0ba | 36 | #include "mbedtls/md2.h" |
marcozecchini | 0:9fca2b23d0ba | 37 | |
marcozecchini | 0:9fca2b23d0ba | 38 | #include <string.h> |
marcozecchini | 0:9fca2b23d0ba | 39 | |
marcozecchini | 0:9fca2b23d0ba | 40 | #if defined(MBEDTLS_SELF_TEST) |
marcozecchini | 0:9fca2b23d0ba | 41 | #if defined(MBEDTLS_PLATFORM_C) |
marcozecchini | 0:9fca2b23d0ba | 42 | #include "mbedtls/platform.h" |
marcozecchini | 0:9fca2b23d0ba | 43 | #else |
marcozecchini | 0:9fca2b23d0ba | 44 | #include <stdio.h> |
marcozecchini | 0:9fca2b23d0ba | 45 | #define mbedtls_printf printf |
marcozecchini | 0:9fca2b23d0ba | 46 | #endif /* MBEDTLS_PLATFORM_C */ |
marcozecchini | 0:9fca2b23d0ba | 47 | #endif /* MBEDTLS_SELF_TEST */ |
marcozecchini | 0:9fca2b23d0ba | 48 | |
marcozecchini | 0:9fca2b23d0ba | 49 | #if !defined(MBEDTLS_MD2_ALT) |
marcozecchini | 0:9fca2b23d0ba | 50 | |
marcozecchini | 0:9fca2b23d0ba | 51 | /* Implementation that should never be optimized out by the compiler */ |
marcozecchini | 0:9fca2b23d0ba | 52 | static void mbedtls_zeroize( void *v, size_t n ) { |
marcozecchini | 0:9fca2b23d0ba | 53 | volatile unsigned char *p = v; while( n-- ) *p++ = 0; |
marcozecchini | 0:9fca2b23d0ba | 54 | } |
marcozecchini | 0:9fca2b23d0ba | 55 | |
marcozecchini | 0:9fca2b23d0ba | 56 | static const unsigned char PI_SUBST[256] = |
marcozecchini | 0:9fca2b23d0ba | 57 | { |
marcozecchini | 0:9fca2b23d0ba | 58 | 0x29, 0x2E, 0x43, 0xC9, 0xA2, 0xD8, 0x7C, 0x01, 0x3D, 0x36, |
marcozecchini | 0:9fca2b23d0ba | 59 | 0x54, 0xA1, 0xEC, 0xF0, 0x06, 0x13, 0x62, 0xA7, 0x05, 0xF3, |
marcozecchini | 0:9fca2b23d0ba | 60 | 0xC0, 0xC7, 0x73, 0x8C, 0x98, 0x93, 0x2B, 0xD9, 0xBC, 0x4C, |
marcozecchini | 0:9fca2b23d0ba | 61 | 0x82, 0xCA, 0x1E, 0x9B, 0x57, 0x3C, 0xFD, 0xD4, 0xE0, 0x16, |
marcozecchini | 0:9fca2b23d0ba | 62 | 0x67, 0x42, 0x6F, 0x18, 0x8A, 0x17, 0xE5, 0x12, 0xBE, 0x4E, |
marcozecchini | 0:9fca2b23d0ba | 63 | 0xC4, 0xD6, 0xDA, 0x9E, 0xDE, 0x49, 0xA0, 0xFB, 0xF5, 0x8E, |
marcozecchini | 0:9fca2b23d0ba | 64 | 0xBB, 0x2F, 0xEE, 0x7A, 0xA9, 0x68, 0x79, 0x91, 0x15, 0xB2, |
marcozecchini | 0:9fca2b23d0ba | 65 | 0x07, 0x3F, 0x94, 0xC2, 0x10, 0x89, 0x0B, 0x22, 0x5F, 0x21, |
marcozecchini | 0:9fca2b23d0ba | 66 | 0x80, 0x7F, 0x5D, 0x9A, 0x5A, 0x90, 0x32, 0x27, 0x35, 0x3E, |
marcozecchini | 0:9fca2b23d0ba | 67 | 0xCC, 0xE7, 0xBF, 0xF7, 0x97, 0x03, 0xFF, 0x19, 0x30, 0xB3, |
marcozecchini | 0:9fca2b23d0ba | 68 | 0x48, 0xA5, 0xB5, 0xD1, 0xD7, 0x5E, 0x92, 0x2A, 0xAC, 0x56, |
marcozecchini | 0:9fca2b23d0ba | 69 | 0xAA, 0xC6, 0x4F, 0xB8, 0x38, 0xD2, 0x96, 0xA4, 0x7D, 0xB6, |
marcozecchini | 0:9fca2b23d0ba | 70 | 0x76, 0xFC, 0x6B, 0xE2, 0x9C, 0x74, 0x04, 0xF1, 0x45, 0x9D, |
marcozecchini | 0:9fca2b23d0ba | 71 | 0x70, 0x59, 0x64, 0x71, 0x87, 0x20, 0x86, 0x5B, 0xCF, 0x65, |
marcozecchini | 0:9fca2b23d0ba | 72 | 0xE6, 0x2D, 0xA8, 0x02, 0x1B, 0x60, 0x25, 0xAD, 0xAE, 0xB0, |
marcozecchini | 0:9fca2b23d0ba | 73 | 0xB9, 0xF6, 0x1C, 0x46, 0x61, 0x69, 0x34, 0x40, 0x7E, 0x0F, |
marcozecchini | 0:9fca2b23d0ba | 74 | 0x55, 0x47, 0xA3, 0x23, 0xDD, 0x51, 0xAF, 0x3A, 0xC3, 0x5C, |
marcozecchini | 0:9fca2b23d0ba | 75 | 0xF9, 0xCE, 0xBA, 0xC5, 0xEA, 0x26, 0x2C, 0x53, 0x0D, 0x6E, |
marcozecchini | 0:9fca2b23d0ba | 76 | 0x85, 0x28, 0x84, 0x09, 0xD3, 0xDF, 0xCD, 0xF4, 0x41, 0x81, |
marcozecchini | 0:9fca2b23d0ba | 77 | 0x4D, 0x52, 0x6A, 0xDC, 0x37, 0xC8, 0x6C, 0xC1, 0xAB, 0xFA, |
marcozecchini | 0:9fca2b23d0ba | 78 | 0x24, 0xE1, 0x7B, 0x08, 0x0C, 0xBD, 0xB1, 0x4A, 0x78, 0x88, |
marcozecchini | 0:9fca2b23d0ba | 79 | 0x95, 0x8B, 0xE3, 0x63, 0xE8, 0x6D, 0xE9, 0xCB, 0xD5, 0xFE, |
marcozecchini | 0:9fca2b23d0ba | 80 | 0x3B, 0x00, 0x1D, 0x39, 0xF2, 0xEF, 0xB7, 0x0E, 0x66, 0x58, |
marcozecchini | 0:9fca2b23d0ba | 81 | 0xD0, 0xE4, 0xA6, 0x77, 0x72, 0xF8, 0xEB, 0x75, 0x4B, 0x0A, |
marcozecchini | 0:9fca2b23d0ba | 82 | 0x31, 0x44, 0x50, 0xB4, 0x8F, 0xED, 0x1F, 0x1A, 0xDB, 0x99, |
marcozecchini | 0:9fca2b23d0ba | 83 | 0x8D, 0x33, 0x9F, 0x11, 0x83, 0x14 |
marcozecchini | 0:9fca2b23d0ba | 84 | }; |
marcozecchini | 0:9fca2b23d0ba | 85 | |
marcozecchini | 0:9fca2b23d0ba | 86 | void mbedtls_md2_init( mbedtls_md2_context *ctx ) |
marcozecchini | 0:9fca2b23d0ba | 87 | { |
marcozecchini | 0:9fca2b23d0ba | 88 | memset( ctx, 0, sizeof( mbedtls_md2_context ) ); |
marcozecchini | 0:9fca2b23d0ba | 89 | } |
marcozecchini | 0:9fca2b23d0ba | 90 | |
marcozecchini | 0:9fca2b23d0ba | 91 | void mbedtls_md2_free( mbedtls_md2_context *ctx ) |
marcozecchini | 0:9fca2b23d0ba | 92 | { |
marcozecchini | 0:9fca2b23d0ba | 93 | if( ctx == NULL ) |
marcozecchini | 0:9fca2b23d0ba | 94 | return; |
marcozecchini | 0:9fca2b23d0ba | 95 | |
marcozecchini | 0:9fca2b23d0ba | 96 | mbedtls_zeroize( ctx, sizeof( mbedtls_md2_context ) ); |
marcozecchini | 0:9fca2b23d0ba | 97 | } |
marcozecchini | 0:9fca2b23d0ba | 98 | |
marcozecchini | 0:9fca2b23d0ba | 99 | void mbedtls_md2_clone( mbedtls_md2_context *dst, |
marcozecchini | 0:9fca2b23d0ba | 100 | const mbedtls_md2_context *src ) |
marcozecchini | 0:9fca2b23d0ba | 101 | { |
marcozecchini | 0:9fca2b23d0ba | 102 | *dst = *src; |
marcozecchini | 0:9fca2b23d0ba | 103 | } |
marcozecchini | 0:9fca2b23d0ba | 104 | |
marcozecchini | 0:9fca2b23d0ba | 105 | /* |
marcozecchini | 0:9fca2b23d0ba | 106 | * MD2 context setup |
marcozecchini | 0:9fca2b23d0ba | 107 | */ |
marcozecchini | 0:9fca2b23d0ba | 108 | void mbedtls_md2_starts( mbedtls_md2_context *ctx ) |
marcozecchini | 0:9fca2b23d0ba | 109 | { |
marcozecchini | 0:9fca2b23d0ba | 110 | memset( ctx->cksum, 0, 16 ); |
marcozecchini | 0:9fca2b23d0ba | 111 | memset( ctx->state, 0, 46 ); |
marcozecchini | 0:9fca2b23d0ba | 112 | memset( ctx->buffer, 0, 16 ); |
marcozecchini | 0:9fca2b23d0ba | 113 | ctx->left = 0; |
marcozecchini | 0:9fca2b23d0ba | 114 | } |
marcozecchini | 0:9fca2b23d0ba | 115 | |
marcozecchini | 0:9fca2b23d0ba | 116 | #if !defined(MBEDTLS_MD2_PROCESS_ALT) |
marcozecchini | 0:9fca2b23d0ba | 117 | void mbedtls_md2_process( mbedtls_md2_context *ctx ) |
marcozecchini | 0:9fca2b23d0ba | 118 | { |
marcozecchini | 0:9fca2b23d0ba | 119 | int i, j; |
marcozecchini | 0:9fca2b23d0ba | 120 | unsigned char t = 0; |
marcozecchini | 0:9fca2b23d0ba | 121 | |
marcozecchini | 0:9fca2b23d0ba | 122 | for( i = 0; i < 16; i++ ) |
marcozecchini | 0:9fca2b23d0ba | 123 | { |
marcozecchini | 0:9fca2b23d0ba | 124 | ctx->state[i + 16] = ctx->buffer[i]; |
marcozecchini | 0:9fca2b23d0ba | 125 | ctx->state[i + 32] = |
marcozecchini | 0:9fca2b23d0ba | 126 | (unsigned char)( ctx->buffer[i] ^ ctx->state[i]); |
marcozecchini | 0:9fca2b23d0ba | 127 | } |
marcozecchini | 0:9fca2b23d0ba | 128 | |
marcozecchini | 0:9fca2b23d0ba | 129 | for( i = 0; i < 18; i++ ) |
marcozecchini | 0:9fca2b23d0ba | 130 | { |
marcozecchini | 0:9fca2b23d0ba | 131 | for( j = 0; j < 48; j++ ) |
marcozecchini | 0:9fca2b23d0ba | 132 | { |
marcozecchini | 0:9fca2b23d0ba | 133 | ctx->state[j] = (unsigned char) |
marcozecchini | 0:9fca2b23d0ba | 134 | ( ctx->state[j] ^ PI_SUBST[t] ); |
marcozecchini | 0:9fca2b23d0ba | 135 | t = ctx->state[j]; |
marcozecchini | 0:9fca2b23d0ba | 136 | } |
marcozecchini | 0:9fca2b23d0ba | 137 | |
marcozecchini | 0:9fca2b23d0ba | 138 | t = (unsigned char)( t + i ); |
marcozecchini | 0:9fca2b23d0ba | 139 | } |
marcozecchini | 0:9fca2b23d0ba | 140 | |
marcozecchini | 0:9fca2b23d0ba | 141 | t = ctx->cksum[15]; |
marcozecchini | 0:9fca2b23d0ba | 142 | |
marcozecchini | 0:9fca2b23d0ba | 143 | for( i = 0; i < 16; i++ ) |
marcozecchini | 0:9fca2b23d0ba | 144 | { |
marcozecchini | 0:9fca2b23d0ba | 145 | ctx->cksum[i] = (unsigned char) |
marcozecchini | 0:9fca2b23d0ba | 146 | ( ctx->cksum[i] ^ PI_SUBST[ctx->buffer[i] ^ t] ); |
marcozecchini | 0:9fca2b23d0ba | 147 | t = ctx->cksum[i]; |
marcozecchini | 0:9fca2b23d0ba | 148 | } |
marcozecchini | 0:9fca2b23d0ba | 149 | } |
marcozecchini | 0:9fca2b23d0ba | 150 | #endif /* !MBEDTLS_MD2_PROCESS_ALT */ |
marcozecchini | 0:9fca2b23d0ba | 151 | |
marcozecchini | 0:9fca2b23d0ba | 152 | /* |
marcozecchini | 0:9fca2b23d0ba | 153 | * MD2 process buffer |
marcozecchini | 0:9fca2b23d0ba | 154 | */ |
marcozecchini | 0:9fca2b23d0ba | 155 | void mbedtls_md2_update( mbedtls_md2_context *ctx, const unsigned char *input, size_t ilen ) |
marcozecchini | 0:9fca2b23d0ba | 156 | { |
marcozecchini | 0:9fca2b23d0ba | 157 | size_t fill; |
marcozecchini | 0:9fca2b23d0ba | 158 | |
marcozecchini | 0:9fca2b23d0ba | 159 | while( ilen > 0 ) |
marcozecchini | 0:9fca2b23d0ba | 160 | { |
marcozecchini | 0:9fca2b23d0ba | 161 | if( ilen > 16 - ctx->left ) |
marcozecchini | 0:9fca2b23d0ba | 162 | fill = 16 - ctx->left; |
marcozecchini | 0:9fca2b23d0ba | 163 | else |
marcozecchini | 0:9fca2b23d0ba | 164 | fill = ilen; |
marcozecchini | 0:9fca2b23d0ba | 165 | |
marcozecchini | 0:9fca2b23d0ba | 166 | memcpy( ctx->buffer + ctx->left, input, fill ); |
marcozecchini | 0:9fca2b23d0ba | 167 | |
marcozecchini | 0:9fca2b23d0ba | 168 | ctx->left += fill; |
marcozecchini | 0:9fca2b23d0ba | 169 | input += fill; |
marcozecchini | 0:9fca2b23d0ba | 170 | ilen -= fill; |
marcozecchini | 0:9fca2b23d0ba | 171 | |
marcozecchini | 0:9fca2b23d0ba | 172 | if( ctx->left == 16 ) |
marcozecchini | 0:9fca2b23d0ba | 173 | { |
marcozecchini | 0:9fca2b23d0ba | 174 | ctx->left = 0; |
marcozecchini | 0:9fca2b23d0ba | 175 | mbedtls_md2_process( ctx ); |
marcozecchini | 0:9fca2b23d0ba | 176 | } |
marcozecchini | 0:9fca2b23d0ba | 177 | } |
marcozecchini | 0:9fca2b23d0ba | 178 | } |
marcozecchini | 0:9fca2b23d0ba | 179 | |
marcozecchini | 0:9fca2b23d0ba | 180 | /* |
marcozecchini | 0:9fca2b23d0ba | 181 | * MD2 final digest |
marcozecchini | 0:9fca2b23d0ba | 182 | */ |
marcozecchini | 0:9fca2b23d0ba | 183 | void mbedtls_md2_finish( mbedtls_md2_context *ctx, unsigned char output[16] ) |
marcozecchini | 0:9fca2b23d0ba | 184 | { |
marcozecchini | 0:9fca2b23d0ba | 185 | size_t i; |
marcozecchini | 0:9fca2b23d0ba | 186 | unsigned char x; |
marcozecchini | 0:9fca2b23d0ba | 187 | |
marcozecchini | 0:9fca2b23d0ba | 188 | x = (unsigned char)( 16 - ctx->left ); |
marcozecchini | 0:9fca2b23d0ba | 189 | |
marcozecchini | 0:9fca2b23d0ba | 190 | for( i = ctx->left; i < 16; i++ ) |
marcozecchini | 0:9fca2b23d0ba | 191 | ctx->buffer[i] = x; |
marcozecchini | 0:9fca2b23d0ba | 192 | |
marcozecchini | 0:9fca2b23d0ba | 193 | mbedtls_md2_process( ctx ); |
marcozecchini | 0:9fca2b23d0ba | 194 | |
marcozecchini | 0:9fca2b23d0ba | 195 | memcpy( ctx->buffer, ctx->cksum, 16 ); |
marcozecchini | 0:9fca2b23d0ba | 196 | mbedtls_md2_process( ctx ); |
marcozecchini | 0:9fca2b23d0ba | 197 | |
marcozecchini | 0:9fca2b23d0ba | 198 | memcpy( output, ctx->state, 16 ); |
marcozecchini | 0:9fca2b23d0ba | 199 | } |
marcozecchini | 0:9fca2b23d0ba | 200 | |
marcozecchini | 0:9fca2b23d0ba | 201 | #endif /* !MBEDTLS_MD2_ALT */ |
marcozecchini | 0:9fca2b23d0ba | 202 | |
marcozecchini | 0:9fca2b23d0ba | 203 | /* |
marcozecchini | 0:9fca2b23d0ba | 204 | * output = MD2( input buffer ) |
marcozecchini | 0:9fca2b23d0ba | 205 | */ |
marcozecchini | 0:9fca2b23d0ba | 206 | void mbedtls_md2( const unsigned char *input, size_t ilen, unsigned char output[16] ) |
marcozecchini | 0:9fca2b23d0ba | 207 | { |
marcozecchini | 0:9fca2b23d0ba | 208 | mbedtls_md2_context ctx; |
marcozecchini | 0:9fca2b23d0ba | 209 | |
marcozecchini | 0:9fca2b23d0ba | 210 | mbedtls_md2_init( &ctx ); |
marcozecchini | 0:9fca2b23d0ba | 211 | mbedtls_md2_starts( &ctx ); |
marcozecchini | 0:9fca2b23d0ba | 212 | mbedtls_md2_update( &ctx, input, ilen ); |
marcozecchini | 0:9fca2b23d0ba | 213 | mbedtls_md2_finish( &ctx, output ); |
marcozecchini | 0:9fca2b23d0ba | 214 | mbedtls_md2_free( &ctx ); |
marcozecchini | 0:9fca2b23d0ba | 215 | } |
marcozecchini | 0:9fca2b23d0ba | 216 | |
marcozecchini | 0:9fca2b23d0ba | 217 | #if defined(MBEDTLS_SELF_TEST) |
marcozecchini | 0:9fca2b23d0ba | 218 | |
marcozecchini | 0:9fca2b23d0ba | 219 | /* |
marcozecchini | 0:9fca2b23d0ba | 220 | * RFC 1319 test vectors |
marcozecchini | 0:9fca2b23d0ba | 221 | */ |
marcozecchini | 0:9fca2b23d0ba | 222 | static const char md2_test_str[7][81] = |
marcozecchini | 0:9fca2b23d0ba | 223 | { |
marcozecchini | 0:9fca2b23d0ba | 224 | { "" }, |
marcozecchini | 0:9fca2b23d0ba | 225 | { "a" }, |
marcozecchini | 0:9fca2b23d0ba | 226 | { "abc" }, |
marcozecchini | 0:9fca2b23d0ba | 227 | { "message digest" }, |
marcozecchini | 0:9fca2b23d0ba | 228 | { "abcdefghijklmnopqrstuvwxyz" }, |
marcozecchini | 0:9fca2b23d0ba | 229 | { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" }, |
marcozecchini | 0:9fca2b23d0ba | 230 | { "12345678901234567890123456789012345678901234567890123456789012" \ |
marcozecchini | 0:9fca2b23d0ba | 231 | "345678901234567890" } |
marcozecchini | 0:9fca2b23d0ba | 232 | }; |
marcozecchini | 0:9fca2b23d0ba | 233 | |
marcozecchini | 0:9fca2b23d0ba | 234 | static const unsigned char md2_test_sum[7][16] = |
marcozecchini | 0:9fca2b23d0ba | 235 | { |
marcozecchini | 0:9fca2b23d0ba | 236 | { 0x83, 0x50, 0xE5, 0xA3, 0xE2, 0x4C, 0x15, 0x3D, |
marcozecchini | 0:9fca2b23d0ba | 237 | 0xF2, 0x27, 0x5C, 0x9F, 0x80, 0x69, 0x27, 0x73 }, |
marcozecchini | 0:9fca2b23d0ba | 238 | { 0x32, 0xEC, 0x01, 0xEC, 0x4A, 0x6D, 0xAC, 0x72, |
marcozecchini | 0:9fca2b23d0ba | 239 | 0xC0, 0xAB, 0x96, 0xFB, 0x34, 0xC0, 0xB5, 0xD1 }, |
marcozecchini | 0:9fca2b23d0ba | 240 | { 0xDA, 0x85, 0x3B, 0x0D, 0x3F, 0x88, 0xD9, 0x9B, |
marcozecchini | 0:9fca2b23d0ba | 241 | 0x30, 0x28, 0x3A, 0x69, 0xE6, 0xDE, 0xD6, 0xBB }, |
marcozecchini | 0:9fca2b23d0ba | 242 | { 0xAB, 0x4F, 0x49, 0x6B, 0xFB, 0x2A, 0x53, 0x0B, |
marcozecchini | 0:9fca2b23d0ba | 243 | 0x21, 0x9F, 0xF3, 0x30, 0x31, 0xFE, 0x06, 0xB0 }, |
marcozecchini | 0:9fca2b23d0ba | 244 | { 0x4E, 0x8D, 0xDF, 0xF3, 0x65, 0x02, 0x92, 0xAB, |
marcozecchini | 0:9fca2b23d0ba | 245 | 0x5A, 0x41, 0x08, 0xC3, 0xAA, 0x47, 0x94, 0x0B }, |
marcozecchini | 0:9fca2b23d0ba | 246 | { 0xDA, 0x33, 0xDE, 0xF2, 0xA4, 0x2D, 0xF1, 0x39, |
marcozecchini | 0:9fca2b23d0ba | 247 | 0x75, 0x35, 0x28, 0x46, 0xC3, 0x03, 0x38, 0xCD }, |
marcozecchini | 0:9fca2b23d0ba | 248 | { 0xD5, 0x97, 0x6F, 0x79, 0xD8, 0x3D, 0x3A, 0x0D, |
marcozecchini | 0:9fca2b23d0ba | 249 | 0xC9, 0x80, 0x6C, 0x3C, 0x66, 0xF3, 0xEF, 0xD8 } |
marcozecchini | 0:9fca2b23d0ba | 250 | }; |
marcozecchini | 0:9fca2b23d0ba | 251 | |
marcozecchini | 0:9fca2b23d0ba | 252 | /* |
marcozecchini | 0:9fca2b23d0ba | 253 | * Checkup routine |
marcozecchini | 0:9fca2b23d0ba | 254 | */ |
marcozecchini | 0:9fca2b23d0ba | 255 | int mbedtls_md2_self_test( int verbose ) |
marcozecchini | 0:9fca2b23d0ba | 256 | { |
marcozecchini | 0:9fca2b23d0ba | 257 | int i; |
marcozecchini | 0:9fca2b23d0ba | 258 | unsigned char md2sum[16]; |
marcozecchini | 0:9fca2b23d0ba | 259 | |
marcozecchini | 0:9fca2b23d0ba | 260 | for( i = 0; i < 7; i++ ) |
marcozecchini | 0:9fca2b23d0ba | 261 | { |
marcozecchini | 0:9fca2b23d0ba | 262 | if( verbose != 0 ) |
marcozecchini | 0:9fca2b23d0ba | 263 | mbedtls_printf( " MD2 test #%d: ", i + 1 ); |
marcozecchini | 0:9fca2b23d0ba | 264 | |
marcozecchini | 0:9fca2b23d0ba | 265 | mbedtls_md2( (unsigned char *) md2_test_str[i], |
marcozecchini | 0:9fca2b23d0ba | 266 | strlen( md2_test_str[i] ), md2sum ); |
marcozecchini | 0:9fca2b23d0ba | 267 | |
marcozecchini | 0:9fca2b23d0ba | 268 | if( memcmp( md2sum, md2_test_sum[i], 16 ) != 0 ) |
marcozecchini | 0:9fca2b23d0ba | 269 | { |
marcozecchini | 0:9fca2b23d0ba | 270 | if( verbose != 0 ) |
marcozecchini | 0:9fca2b23d0ba | 271 | mbedtls_printf( "failed\n" ); |
marcozecchini | 0:9fca2b23d0ba | 272 | |
marcozecchini | 0:9fca2b23d0ba | 273 | return( 1 ); |
marcozecchini | 0:9fca2b23d0ba | 274 | } |
marcozecchini | 0:9fca2b23d0ba | 275 | |
marcozecchini | 0:9fca2b23d0ba | 276 | if( verbose != 0 ) |
marcozecchini | 0:9fca2b23d0ba | 277 | mbedtls_printf( "passed\n" ); |
marcozecchini | 0:9fca2b23d0ba | 278 | } |
marcozecchini | 0:9fca2b23d0ba | 279 | |
marcozecchini | 0:9fca2b23d0ba | 280 | if( verbose != 0 ) |
marcozecchini | 0:9fca2b23d0ba | 281 | mbedtls_printf( "\n" ); |
marcozecchini | 0:9fca2b23d0ba | 282 | |
marcozecchini | 0:9fca2b23d0ba | 283 | return( 0 ); |
marcozecchini | 0:9fca2b23d0ba | 284 | } |
marcozecchini | 0:9fca2b23d0ba | 285 | |
marcozecchini | 0:9fca2b23d0ba | 286 | #endif /* MBEDTLS_SELF_TEST */ |
marcozecchini | 0:9fca2b23d0ba | 287 | |
marcozecchini | 0:9fca2b23d0ba | 288 | #endif /* MBEDTLS_MD2_C */ |