diff options
author | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2017-07-14 09:10:11 +0200 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2018-02-19 15:29:33 +0100 |
commit | 35662d783dd280e911afcd483d38490e42c284b9 (patch) | |
tree | 4d6392efcca718c13b41e71fa71ca2ab14f9deeb /lib/str.c | |
parent | 9632471f3ae26cd8e2c586c3e638f2c16fa905b2 (diff) | |
download | gnutls-35662d783dd280e911afcd483d38490e42c284b9.tar.gz |
str: added function to append fixed-size MPI
This is used in TLS 1.3 which introduces a new MPI over-the-wire
format.
Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
Diffstat (limited to 'lib/str.c')
-rw-r--r-- | lib/str.c | 37 |
1 files changed, 37 insertions, 0 deletions
@@ -1,5 +1,6 @@ /* * Copyright (C) 2002-2012 Free Software Foundation, Inc. + * Copyright (C) 2016-2017 Red Hat, Inc. * * Author: Nikos Mavrogiannopoulos * @@ -869,6 +870,42 @@ int _gnutls_buffer_append_mpi(gnutls_buffer_st * buf, int pfx_size, return ret; } +/* Appends an MPI of fixed-size in bytes left-padded with zeros if necessary */ +int _gnutls_buffer_append_fixed_mpi(gnutls_buffer_st * buf, + bigint_t mpi, unsigned size) +{ + gnutls_datum_t dd; + unsigned pad, i; + int ret; + + ret = _gnutls_mpi_dprint(mpi, &dd); + if (ret < 0) + return gnutls_assert_val(ret); + + if (size < dd.size) { + ret = gnutls_assert_val(GNUTLS_E_INVALID_REQUEST); + goto cleanup; + } + + pad = size - dd.size; + for (i=0;i<pad;i++) { + ret = + _gnutls_buffer_append_data(buf, "\x00", 1); + if (ret < 0) { + gnutls_assert(); + goto cleanup; + } + } + + /* append the rest */ + ret = + _gnutls_buffer_append_data(buf, dd.data, dd.size); + + cleanup: + _gnutls_free_datum(&dd); + return ret; +} + void _gnutls_buffer_hexprint(gnutls_buffer_st * str, const void *_data, size_t len) |