summary refs log tree commit diff
path: root/crypto/src/tls/MacAlgorithm.cs
blob: 1706de1bda773f4a4fa42281c2e0086082183917 (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
61
62
63
64
65
66
using System;

namespace Org.BouncyCastle.Tls
{
    /// <summary>RFC 2246</summary>
    /// <remarks>
    /// Note that the values here are implementation-specific and arbitrary. It is recommended not to depend on the
    /// particular values (e.g. serialization).
    /// </remarks>
    public abstract class MacAlgorithm
    {
        public const int cls_null = 0;
        public const int md5 = 1;
        public const int sha = 2;

        /*
         * RFC 5246
         */
        public const int hmac_md5 = md5;
        public const int hmac_sha1 = sha;
        public const int hmac_sha256 = 3;
        public const int hmac_sha384 = 4;
        public const int hmac_sha512 = 5;

        public static string GetName(int macAlgorithm)
        {
            switch (macAlgorithm)
            {
            case cls_null:
                return "null";
            case hmac_md5:
                return "hmac_md5";
            case hmac_sha1:
                return "hmac_sha1";
            case hmac_sha256:
                return "hmac_sha256";
            case hmac_sha384:
                return "hmac_sha384";
            case hmac_sha512:
                return "hmac_sha512";
            default:
                return "UNKNOWN";
            }
        }

        public static string GetText(int macAlgorithm)
        {
            return GetName(macAlgorithm) + "(" + macAlgorithm + ")";
        }

        public static bool IsHmac(int macAlgorithm)
        {
            switch (macAlgorithm)
            {
            case hmac_md5:
            case hmac_sha1:
            case hmac_sha256:
            case hmac_sha384:
            case hmac_sha512:
                return true;
            default:
                return false;
            }
        }
    }
}