2 * Copyright (c) 2020 Yubico AB. All rights reserved.
3 * Use of this source code is governed by a BSD-style
4 * license that can be found in the LICENSE file.
10 #define BOUND (1024UL * 1024UL)
13 do_compress(fido_blob_t *out, const fido_blob_t *in, size_t origsiz, int decomp)
18 memset(out, 0, sizeof(*out));
19 if (in->len > ULONG_MAX || (ilen = (u_long)in->len) > BOUND ||
20 origsiz > ULONG_MAX || (olen = decomp ? (u_long)origsiz :
21 compressBound(ilen)) > BOUND)
22 return FIDO_ERR_INVALID_ARGUMENT;
23 if ((out->ptr = calloc(1, olen)) == NULL)
24 return FIDO_ERR_INTERNAL;
27 r = uncompress(out->ptr, &olen, in->ptr, ilen);
29 r = compress(out->ptr, &olen, in->ptr, ilen);
30 if (r != Z_OK || olen > SIZE_MAX || olen > out->len) {
32 return FIDO_ERR_COMPRESS;
40 fido_compress(fido_blob_t *out, const fido_blob_t *in)
42 return do_compress(out, in, 0, 0);
46 fido_uncompress(fido_blob_t *out, const fido_blob_t *in, size_t origsiz)
48 return do_compress(out, in, origsiz, 1);