]> pd.if.org Git - zpackage/blob - crypto/cipher_supported.c
add option to determine name from url
[zpackage] / crypto / cipher_supported.c
1 #include "tlse.h"
2
3 int tls_cipher_supported(struct TLSContext *context, unsigned short cipher) {
4         if (!context) {
5                 return 0;
6         }
7
8         switch (cipher) {
9                 case TLS_AES_128_GCM_SHA256:
10                 case TLS_AES_256_GCM_SHA384:
11                 case TLS_CHACHA20_POLY1305_SHA256:
12                         if (context->tlsver == TLS_VERSION13) {
13                                 return 1;
14                         }
15                         return 0;
16                 case TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA:
17                 case TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA:
18                         if (context && ((context->certificates
19                                                         && context->certificates_count
20                                                         && context->ec_private_key)
21                                                 || !context->is_server)) {
22                                 return 1;
23                         }
24                         return 0;
25                 case TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256:
26                 case TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384:
27                 case TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256:
28                 case TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384:
29                 case TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256:
30                         if (context->tlsver == TLS_VERSION12) {
31                                 if (context && ((context->certificates
32                                                                 && context->certificates_count
33                                                                 && context->ec_private_key)
34                                                         || !context->is_server)) {
35                                         return 1;
36                                 }
37                         }
38                         return 0;
39                 case TLS_DHE_RSA_WITH_AES_128_CBC_SHA:
40                 case TLS_DHE_RSA_WITH_AES_256_CBC_SHA:
41                 case TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA:
42                 case TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA:
43                 case TLS_RSA_WITH_AES_128_CBC_SHA:
44                 case TLS_RSA_WITH_AES_256_CBC_SHA:
45                         return 1;
46                 case TLS_DHE_RSA_WITH_AES_128_CBC_SHA256:
47                 case TLS_DHE_RSA_WITH_AES_256_CBC_SHA256:
48                 case TLS_DHE_RSA_WITH_AES_128_GCM_SHA256:
49                 case TLS_DHE_RSA_WITH_AES_256_GCM_SHA384:
50                 case TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256:
51                 case TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256:
52                 case TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384:
53                 case TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256:
54                 case TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256:
55                 case TLS_RSA_WITH_AES_128_GCM_SHA256:
56                 case TLS_RSA_WITH_AES_128_CBC_SHA256:
57                 case TLS_RSA_WITH_AES_256_CBC_SHA256:
58                 case TLS_RSA_WITH_AES_256_GCM_SHA384:
59                         if (context->tlsver == TLS_VERSION12) {
60                                 return 1;
61                         }
62                         return 0;
63         }
64         return 0;
65 }