1295367Sdes/* $OpenBSD: bufec.c,v 1.4 2014/04/30 05:29:56 djm Exp $ */
2295367Sdes
3218767Sdes/*
4295367Sdes * Copyright (c) 2012 Damien Miller <djm@mindrot.org>
5218767Sdes *
6218767Sdes * Permission to use, copy, modify, and distribute this software for any
7218767Sdes * purpose with or without fee is hereby granted, provided that the above
8218767Sdes * copyright notice and this permission notice appear in all copies.
9218767Sdes *
10218767Sdes * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11218767Sdes * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12218767Sdes * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13218767Sdes * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14218767Sdes * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15218767Sdes * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16218767Sdes * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17218767Sdes */
18218767Sdes
19295367Sdes/* Emulation wrappers for legacy OpenSSH buffer API atop sshbuf */
20295367Sdes
21218767Sdes#include "includes.h"
22218767Sdes
23218767Sdes#include <sys/types.h>
24218767Sdes
25218767Sdes#include "buffer.h"
26218767Sdes#include "log.h"
27295367Sdes#include "ssherr.h"
28218767Sdes
29295367Sdes#ifdef OPENSSL_HAS_ECC
30218767Sdes
31218767Sdesint
32218767Sdesbuffer_put_ecpoint_ret(Buffer *buffer, const EC_GROUP *curve,
33218767Sdes    const EC_POINT *point)
34218767Sdes{
35295367Sdes	int ret;
36218767Sdes
37295367Sdes	if ((ret = sshbuf_put_ec(buffer, point, curve)) != 0) {
38295367Sdes		error("%s: %s", __func__, ssh_err(ret));
39295367Sdes		return -1;
40218767Sdes	}
41295367Sdes	return 0;
42218767Sdes}
43218767Sdes
44218767Sdesvoid
45218767Sdesbuffer_put_ecpoint(Buffer *buffer, const EC_GROUP *curve,
46218767Sdes    const EC_POINT *point)
47218767Sdes{
48218767Sdes	if (buffer_put_ecpoint_ret(buffer, curve, point) == -1)
49218767Sdes		fatal("%s: buffer error", __func__);
50218767Sdes}
51218767Sdes
52218767Sdesint
53218767Sdesbuffer_get_ecpoint_ret(Buffer *buffer, const EC_GROUP *curve,
54218767Sdes    EC_POINT *point)
55218767Sdes{
56295367Sdes	int ret;
57218767Sdes
58295367Sdes	if ((ret = sshbuf_get_ec(buffer, point, curve)) != 0) {
59295367Sdes		error("%s: %s", __func__, ssh_err(ret));
60218767Sdes		return -1;
61218767Sdes	}
62295367Sdes	return 0;
63218767Sdes}
64218767Sdes
65218767Sdesvoid
66218767Sdesbuffer_get_ecpoint(Buffer *buffer, const EC_GROUP *curve,
67218767Sdes    EC_POINT *point)
68218767Sdes{
69218767Sdes	if (buffer_get_ecpoint_ret(buffer, curve, point) == -1)
70218767Sdes		fatal("%s: buffer error", __func__);
71218767Sdes}
72218767Sdes
73218767Sdes#endif /* OPENSSL_HAS_ECC */
74295367Sdes
75