1263970Sdes/* $OpenBSD: digest.h,v 1.2 2014/01/27 18:58:14 markus Exp $ */ 2261287Sdes/* 3261287Sdes * Copyright (c) 2013 Damien Miller <djm@mindrot.org> 4261287Sdes * 5261287Sdes * Permission to use, copy, modify, and distribute this software for any 6261287Sdes * purpose with or without fee is hereby granted, provided that the above 7261287Sdes * copyright notice and this permission notice appear in all copies. 8261287Sdes * 9261287Sdes * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10261287Sdes * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11261287Sdes * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12261287Sdes * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13261287Sdes * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14261287Sdes * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15261287Sdes * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16261287Sdes */ 17261287Sdes 18261287Sdes#ifndef _DIGEST_H 19261287Sdes#define _DIGEST_H 20261287Sdes 21261287Sdes/* Maximum digest output length */ 22261287Sdes#define SSH_DIGEST_MAX_LENGTH 64 23261287Sdes 24261287Sdes/* Digest algorithms */ 25261287Sdes#define SSH_DIGEST_MD5 0 26261287Sdes#define SSH_DIGEST_RIPEMD160 1 27261287Sdes#define SSH_DIGEST_SHA1 2 28261287Sdes#define SSH_DIGEST_SHA256 3 29261287Sdes#define SSH_DIGEST_SHA384 4 30261287Sdes#define SSH_DIGEST_SHA512 5 31261287Sdes#define SSH_DIGEST_MAX 6 32261287Sdes 33263970Sdesstruct ssh_digest_ctx; 34263970Sdes 35261287Sdes/* Returns the algorithm's digest length in bytes or 0 for invalid algorithm */ 36261287Sdessize_t ssh_digest_bytes(int alg); 37261287Sdes 38263970Sdes/* Returns the block size of the digest, e.g. for implementing HMAC */ 39263970Sdessize_t ssh_digest_blocksize(struct ssh_digest_ctx *ctx); 40263970Sdes 41263970Sdes/* Copies internal state of digest of 'from' to 'to' */ 42263970Sdesint ssh_digest_copy_state(struct ssh_digest_ctx *from, 43263970Sdes struct ssh_digest_ctx *to); 44263970Sdes 45261287Sdes/* One-shot API */ 46261287Sdesint ssh_digest_memory(int alg, const void *m, size_t mlen, 47261287Sdes u_char *d, size_t dlen) 48261287Sdes __attribute__((__bounded__(__buffer__, 2, 3))) 49261287Sdes __attribute__((__bounded__(__buffer__, 4, 5))); 50261287Sdesint ssh_digest_buffer(int alg, const Buffer *b, u_char *d, size_t dlen) 51261287Sdes __attribute__((__bounded__(__buffer__, 3, 4))); 52261287Sdes 53261287Sdes/* Update API */ 54261287Sdesstruct ssh_digest_ctx *ssh_digest_start(int alg); 55261287Sdesint ssh_digest_update(struct ssh_digest_ctx *ctx, const void *m, size_t mlen) 56261287Sdes __attribute__((__bounded__(__buffer__, 2, 3))); 57261287Sdesint ssh_digest_update_buffer(struct ssh_digest_ctx *ctx, const Buffer *b); 58261287Sdesint ssh_digest_final(struct ssh_digest_ctx *ctx, u_char *d, size_t dlen) 59261287Sdes __attribute__((__bounded__(__buffer__, 2, 3))); 60261287Sdesvoid ssh_digest_free(struct ssh_digest_ctx *ctx); 61261287Sdes 62261287Sdes#endif /* _DIGEST_H */ 63261287Sdes 64