1/*	$NetBSD$	*/
2/* $OpenBSD: schnorr.h,v 1.1 2009/03/05 07:18:19 djm Exp $ */
3/*
4 * Copyright (c) 2009 Damien Miller.  All rights reserved.
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19#ifndef SCHNORR_H
20#define SCHNORR_H
21
22#include <sys/types.h>
23
24#include <openssl/bn.h>
25
26struct modp_group {
27	BIGNUM *p, *q, *g;
28};
29
30BIGNUM *bn_rand_range_gt_one(const BIGNUM *high);
31int hash_buffer(const u_char *, u_int, const EVP_MD *, u_char **, u_int *);
32void debug3_bn(const BIGNUM *, const char *, ...)
33    __attribute__((__nonnull__ (2)))
34    __attribute__((format(printf, 2, 3)));
35void debug3_buf(const u_char *, u_int, const char *, ...)
36    __attribute__((__nonnull__ (3)))
37    __attribute__((format(printf, 3, 4)));
38struct modp_group *modp_group_from_g_and_safe_p(const char *, const char *);
39void modp_group_free(struct modp_group *);
40
41/* Signature and verification functions */
42int
43schnorr_sign(const BIGNUM *grp_p, const BIGNUM *grp_q, const BIGNUM *grp_g,
44    const EVP_MD *evp_md, const BIGNUM *x, const BIGNUM *g_x,
45    const u_char *id, u_int idlen, BIGNUM **r_p, BIGNUM **e_p);
46int
47schnorr_sign_buf(const BIGNUM *grp_p, const BIGNUM *grp_q, const BIGNUM *grp_g,
48    const BIGNUM *x, const BIGNUM *g_x, const u_char *id, u_int idlen,
49    u_char **sig, u_int *siglen);
50int
51schnorr_verify(const BIGNUM *grp_p, const BIGNUM *grp_q, const BIGNUM *grp_g,
52    const EVP_MD *evp_md, const BIGNUM *g_x, const u_char *id, u_int idlen,
53    const BIGNUM *r, const BIGNUM *e);
54int
55schnorr_verify_buf(const BIGNUM *grp_p, const BIGNUM *grp_q,
56    const BIGNUM *grp_g,
57    const BIGNUM *g_x, const u_char *id, u_int idlen,
58    const u_char *sig, u_int siglen);
59
60#endif /* JPAKE_H */
61
62