Home | History | Annotate | Download | only in openssh
      1 /* $OpenBSD: bufec.c,v 1.4 2014/04/30 05:29:56 djm Exp $ */
      2 
      3 /*
      4  * Copyright (c) 2012 Damien Miller <djm (at) mindrot.org>
      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 /* Emulation wrappers for legacy OpenSSH buffer API atop sshbuf */
     20 
     21 #include "includes.h"
     22 
     23 #include <sys/types.h>
     24 
     25 #include "buffer.h"
     26 #include "log.h"
     27 #include "ssherr.h"
     28 
     29 #ifdef OPENSSL_HAS_ECC
     30 
     31 int
     32 buffer_put_ecpoint_ret(Buffer *buffer, const EC_GROUP *curve,
     33     const EC_POINT *point)
     34 {
     35 	int ret;
     36 
     37 	if ((ret = sshbuf_put_ec(buffer, point, curve)) != 0) {
     38 		error("%s: %s", __func__, ssh_err(ret));
     39 		return -1;
     40 	}
     41 	return 0;
     42 }
     43 
     44 void
     45 buffer_put_ecpoint(Buffer *buffer, const EC_GROUP *curve,
     46     const EC_POINT *point)
     47 {
     48 	if (buffer_put_ecpoint_ret(buffer, curve, point) == -1)
     49 		fatal("%s: buffer error", __func__);
     50 }
     51 
     52 int
     53 buffer_get_ecpoint_ret(Buffer *buffer, const EC_GROUP *curve,
     54     EC_POINT *point)
     55 {
     56 	int ret;
     57 
     58 	if ((ret = sshbuf_get_ec(buffer, point, curve)) != 0) {
     59 		error("%s: %s", __func__, ssh_err(ret));
     60 		return -1;
     61 	}
     62 	return 0;
     63 }
     64 
     65 void
     66 buffer_get_ecpoint(Buffer *buffer, const EC_GROUP *curve,
     67     EC_POINT *point)
     68 {
     69 	if (buffer_get_ecpoint_ret(buffer, curve, point) == -1)
     70 		fatal("%s: buffer error", __func__);
     71 }
     72 
     73 #endif /* OPENSSL_HAS_ECC */
     74 
     75