summary refs log tree commit diff
path: root/crypto/src/pqc/asn1/KyberPublicKey.cs
blob: 9f162e3347ceca0e1817b0474e9a3480087ca96c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;

using Org.BouncyCastle.Asn1;
using Org.BouncyCastle.Utilities;

namespace Org.BouncyCastle.Pqc.Asn1
{
    /**
     *    Crystal Kyber Public Key Format.
     *    See https://www.ietf.org/archive/id/draft-uni-qsckeys-kyber-00.html for details.
     *    <pre>
     *        KyberPublicKey ::= SEQUENCE {
     *         t           OCTET STRING,
     *         rho         OCTET STRING
     *     }
     *    </pre>
     */
    [Obsolete("Will be removed as this draft proposal was rejected")]
    public sealed class KyberPublicKey
        : Asn1Encodable
    {
        public static KyberPublicKey GetInstance(object obj)
        {
            if (obj == null)
                return null;
            if (obj is KyberPublicKey kyberPublicKey)
                return kyberPublicKey;
            return new KyberPublicKey(Asn1Sequence.GetInstance(obj));
        }

        public static KyberPublicKey GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
        {
            return GetInstance(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
        }

        private readonly byte[] m_t;
        private readonly byte[] m_rho;

        public KyberPublicKey(byte[] t, byte[] rho)
        {
            m_t = t;
            m_rho = rho;
        }

        private KyberPublicKey(Asn1Sequence seq)
        {
            m_t = Arrays.Clone(Asn1OctetString.GetInstance(seq[0]).GetOctets());
            m_rho = Arrays.Clone(Asn1OctetString.GetInstance(seq[1]).GetOctets());
        }

        public byte[] T => Arrays.Clone(m_t);

        public byte[] Rho => Arrays.Clone(m_rho);

        public override Asn1Object ToAsn1Object()
        {
            return new DerSequence(new DerOctetString(m_t), new DerOctetString(m_rho));
        }
    }
}