0

I have to represent (ASN.1/DER SEQUENCE) pseudocode:

SEQUENCE ::= {
      INTEGER
      SEQUENCE {...}
      ...
}

Where INTEGER should be a PUBLIC KEY

In terms of Golang struct I have so far pseudocode:

type ... struct {
      num int64,
      ...
}

But when compile, I got runtime error, saying:

panic: asn1: structure error: integer too large

I understand, that problem is with fitting LARGE PUBLIC KEY into small int64, how should I overcome that problem? When I change num int64 to num []int64 I got another error, saying, that type mismatch (which also MAKE SENSE, since was INTEGER and now SEQUENCE)...

So, again, how do you fit PUBLIC KEY INTEGER into int of Golang or any other prog. lang?

ojacomarket
  • 493
  • 2
  • 7
  • 2
    If the integer value is larger than 64 bits, then of course you cannot fit it into an int64. From the `encoding/asn1` docs: _`An ASN.1 INTEGER can be written to an int, int32, int64, or *big.Int`_ – JimB Mar 02 '22 at 17:10
  • @JimB yeah, that's it.. but Big.Int in Go is a struct and not int128, and as you know all structs from ASN.1 point of view are SEQUENCEs and not INTEGERs.. :( – ojacomarket Mar 03 '22 at 07:37

2 Answers2

1

I think this could help you: Why is unmarshalling of a DER ASN.1 large integer limited to SEQUENCE in Golang? (look at the answer)

Note on your comment: Go Big.Int is NOT an asn1 SEQUENCE (asn1 is agnostic, it is up to you or the tool you use to define how you will map asn1 INTEGER to something you can use)

YaFred
  • 9,698
  • 3
  • 28
  • 40
0

ASN.1 does not put a limit on the size of an INTEGER, which is one reason INTEGER is used to represent the large public key. Several programming languages have a "Big.INT" representation that can be used to handle such large integers. Some commercial ASN.1 Tools have an alternate representation for handling such large integers in target languages such as C or C++ which don't have a Big INT representation. In your case, int64 is not sufficient to handle public key integer which can be more than 128 bits in length. You will need to determine how your ASN.1 tool handles huge integers, or you may consider using an ASN.1 tool that does support big integers.

Paul Thorpe
  • 1,930
  • 17
  • 23
  • Thanks for quick response! In Go there is Big.Int indeed, however from ASN.1 point of view the Big.Int is a SEQUENCE :( and not INTEGER. Btw, in Go, Big.Int is defined as struct and that what makes it very confusing, since I have no idea how to interpret struct as int in such way, that ASN.1 could see it as INTEGER and not SEQUENCE... – ojacomarket Mar 03 '22 at 07:35
  • I see that YaFred gave the link https://stackoverflow.com/questions/53139020/why-is-unmarshalling-of-a-der-asn-1-large-integer-limited-to-sequence-in-golang which explains the solution for Golang. – Paul Thorpe Mar 03 '22 at 18:27