Sha256: f60a7003e16aaf17c33d91a6406b47d8279018e573595aa12b7a58f2538d730c

Contents?: true

Size: 1.83 KB

Versions: 106

Compression:

Stored size: 1.83 KB

Contents

/* Copyright (c) 2015, Google Inc.
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */

#include <openssl/bn.h>

#include <openssl/bytestring.h>
#include <openssl/err.h>


int BN_parse_asn1_unsigned(CBS *cbs, BIGNUM *ret) {
  CBS child;
  int is_negative;
  if (!CBS_get_asn1(cbs, &child, CBS_ASN1_INTEGER) ||
      !CBS_is_valid_asn1_integer(&child, &is_negative)) {
    OPENSSL_PUT_ERROR(BN, BN_R_BAD_ENCODING);
    return 0;
  }

  if (is_negative) {
    OPENSSL_PUT_ERROR(BN, BN_R_NEGATIVE_NUMBER);
    return 0;
  }

  return BN_bin2bn(CBS_data(&child), CBS_len(&child), ret) != NULL;
}

int BN_marshal_asn1(CBB *cbb, const BIGNUM *bn) {
  // Negative numbers are unsupported.
  if (BN_is_negative(bn)) {
    OPENSSL_PUT_ERROR(BN, BN_R_NEGATIVE_NUMBER);
    return 0;
  }

  CBB child;
  if (!CBB_add_asn1(cbb, &child, CBS_ASN1_INTEGER) ||
      // The number must be padded with a leading zero if the high bit would
      // otherwise be set or if |bn| is zero.
      (BN_num_bits(bn) % 8 == 0 && !CBB_add_u8(&child, 0x00)) ||
      !BN_bn2cbb_padded(&child, BN_num_bytes(bn), bn) ||
      !CBB_flush(cbb)) {
    OPENSSL_PUT_ERROR(BN, BN_R_ENCODE_ERROR);
    return 0;
  }

  return 1;
}

Version data entries

106 entries across 106 versions & 5 rubygems

Version Path
grpc-1.53.2 third_party/boringssl-with-bazel/src/crypto/bn_extra/bn_asn1.c
grpc-1.55.3 third_party/boringssl-with-bazel/src/crypto/bn_extra/bn_asn1.c
grpc-1.57.0.pre1 third_party/boringssl-with-bazel/src/crypto/bn_extra/bn_asn1.c
grpc-1.56.2 third_party/boringssl-with-bazel/src/crypto/bn_extra/bn_asn1.c
rubypitaya-3.12.5 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/grpc-1.50.0-x86_64-linux/third_party/boringssl-with-bazel/src/crypto/bn_extra/bn_asn1.c
grpc-1.56.0 third_party/boringssl-with-bazel/src/crypto/bn_extra/bn_asn1.c
grpc-1.56.0.pre3 third_party/boringssl-with-bazel/src/crypto/bn_extra/bn_asn1.c
grpc-1.55.0 third_party/boringssl-with-bazel/src/crypto/bn_extra/bn_asn1.c
grpc-1.53.1 third_party/boringssl-with-bazel/src/crypto/bn_extra/bn_asn1.c
grpc-1.52.2 third_party/boringssl-with-bazel/src/crypto/bn_extra/bn_asn1.c
grpc-1.54.2 third_party/boringssl-with-bazel/src/crypto/bn_extra/bn_asn1.c
grpc-1.54.0 third_party/boringssl-with-bazel/src/crypto/bn_extra/bn_asn1.c
aws-crt-0.1.8 aws-crt-ffi/crt/aws-lc/crypto/bn_extra/bn_asn1.c
grpc-1.53.0 third_party/boringssl-with-bazel/src/crypto/bn_extra/bn_asn1.c
grpc-1.53.0.pre2 third_party/boringssl-with-bazel/src/crypto/bn_extra/bn_asn1.c
grpc-1.52.0 third_party/boringssl-with-bazel/src/crypto/bn_extra/bn_asn1.c
aws-crt-0.1.7 aws-crt-ffi/crt/aws-lc/crypto/bn_extra/bn_asn1.c
rubypitaya-3.12.4 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/grpc-1.50.0-x86_64-linux/third_party/boringssl-with-bazel/src/crypto/bn_extra/bn_asn1.c
grpc-1.51.0-x86_64-linux third_party/boringssl-with-bazel/src/crypto/bn_extra/bn_asn1.c
grpc-1.51.0 third_party/boringssl-with-bazel/src/crypto/bn_extra/bn_asn1.c