diff options
author | jsing <> | 2018-01-27 15:09:15 +0000 |
---|---|---|
committer | jsing <> | 2018-01-27 15:09:15 +0000 |
commit | 6c88052565f5aa652eb289ad03c924a369d18397 (patch) | |
tree | f930a95329ff48144125c57d68e0678af1ac29f7 | |
parent | 8df22ba873a3a23abdc070f97ee5a5d08cbbb8db (diff) | |
download | openbsd-6c88052565f5aa652eb289ad03c924a369d18397.tar.gz openbsd-6c88052565f5aa652eb289ad03c924a369d18397.tar.bz2 openbsd-6c88052565f5aa652eb289ad03c924a369d18397.zip |
Convert ssl3_put_cipher_by_char() to CBB.
While here make the CBS usage in ssl3_get_cipher_by_char() more consistent
with other code.
ok inoguchi@
-rw-r--r-- | src/lib/libssl/s3_lib.c | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/src/lib/libssl/s3_lib.c b/src/lib/libssl/s3_lib.c index 89af1ef3bf..a15003b053 100644 --- a/src/lib/libssl/s3_lib.c +++ b/src/lib/libssl/s3_lib.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: s3_lib.c,v 1.162 2017/10/08 16:24:02 jsing Exp $ */ | 1 | /* $OpenBSD: s3_lib.c,v 1.163 2018/01/27 15:09:15 jsing Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -2298,12 +2298,12 @@ ssl3_ctx_callback_ctrl(SSL_CTX *ctx, int cmd, void (*fp)(void)) | |||
2298 | const SSL_CIPHER * | 2298 | const SSL_CIPHER * |
2299 | ssl3_get_cipher_by_char(const unsigned char *p) | 2299 | ssl3_get_cipher_by_char(const unsigned char *p) |
2300 | { | 2300 | { |
2301 | CBS cipher; | ||
2302 | uint16_t cipher_value; | 2301 | uint16_t cipher_value; |
2302 | CBS cbs; | ||
2303 | 2303 | ||
2304 | /* We have to assume it is at least 2 bytes due to existing API. */ | 2304 | /* We have to assume it is at least 2 bytes due to existing API. */ |
2305 | CBS_init(&cipher, p, 2); | 2305 | CBS_init(&cbs, p, 2); |
2306 | if (!CBS_get_u16(&cipher, &cipher_value)) | 2306 | if (!CBS_get_u16(&cbs, &cipher_value)) |
2307 | return NULL; | 2307 | return NULL; |
2308 | 2308 | ||
2309 | return ssl3_get_cipher_by_value(cipher_value); | 2309 | return ssl3_get_cipher_by_value(cipher_value); |
@@ -2312,12 +2312,29 @@ ssl3_get_cipher_by_char(const unsigned char *p) | |||
2312 | int | 2312 | int |
2313 | ssl3_put_cipher_by_char(const SSL_CIPHER *c, unsigned char *p) | 2313 | ssl3_put_cipher_by_char(const SSL_CIPHER *c, unsigned char *p) |
2314 | { | 2314 | { |
2315 | if (p != NULL) { | 2315 | CBB cbb; |
2316 | if ((c->id & ~SSL3_CK_VALUE_MASK) != SSL3_CK_ID) | 2316 | |
2317 | return (0); | 2317 | if (p == NULL) |
2318 | s2n(ssl3_cipher_get_value(c), p); | 2318 | return (2); |
2319 | } | 2319 | |
2320 | if ((c->id & ~SSL3_CK_VALUE_MASK) != SSL3_CK_ID) | ||
2321 | return (0); | ||
2322 | |||
2323 | memset(&cbb, 0, sizeof(cbb)); | ||
2324 | |||
2325 | /* We have to assume it is at least 2 bytes due to existing API. */ | ||
2326 | if (!CBB_init_fixed(&cbb, p, 2)) | ||
2327 | goto err; | ||
2328 | if (!CBB_add_u16(&cbb, ssl3_cipher_get_value(c))) | ||
2329 | goto err; | ||
2330 | if (!CBB_finish(&cbb, NULL, NULL)) | ||
2331 | goto err; | ||
2332 | |||
2320 | return (2); | 2333 | return (2); |
2334 | |||
2335 | err: | ||
2336 | CBB_cleanup(&cbb); | ||
2337 | return (0); | ||
2321 | } | 2338 | } |
2322 | 2339 | ||
2323 | SSL_CIPHER * | 2340 | SSL_CIPHER * |