Showcase

Code view:

A painting is a person's account of this edit as text, recorded independently of the node mapping - a rendering often has several equally defensible answers where the mapping has one. Deletions and insertions carry no position on the opposite side in a painting, so that panel draws no caret for them.

Before

…lines 1–240 unchanged (240 lines)
241 { OSSL_FUNC_KDF_SET_CTX_PARAMS, (void (*)(void))kdf_snmpkdf_set_ctx_params },
242 { OSSL_FUNC_KDF_GETTABLE_CTX_PARAMS,
243 (void (*)(void))kdf_snmpkdf_gettable_ctx_params },
244 { OSSL_FUNC_KDF_GET_CTX_PARAMS, (void (*)(void))kdf_snmpkdf_get_ctx_params },
245 { 0, NULL }
246};
247
248/*
249 * SNMPKDF - In compliance with SP800-135 and RFC7860, calculate
250 * a master key using the engine ID and password.
251 *
252 * Denote engineLength and passwordlen to be the lengths (in bytes) of an
253 * snmpEngineID and a password, respectively.
…lines 254–261 unchanged (8 lines)
262 *
263 * Let Shared_key to be the key that the user shares with the authoritative
264 * SNMP engine with ID snmpEngineID. The Shared_key is generated as follows:
265 *
266 * Shared_key = SHA-1(Derived_password || snmpEngineID || Derived_password).
267 *
268 * e_id - engine ID(eid)
269 * e_len - engineID length
270 * password - password
271 * password_len - password length
272 * okey - pointer to key output, FIPS testing limited to SHA-1.
273 * okeylen - key output length
274 * return - 1 pass 0 for error
275 */
276static int SNMPKDF(const EVP_MD *evp_md,
277 const unsigned char *e_id, size_t e_len,
278 unsigned char *password, size_t password_len,
279 unsigned char *okey, size_t okeylen)
280{
281 EVP_MD_CTX *md = NULL;
282 unsigned char digest[EVP_MAX_MD_SIZE];
283 size_t mdsize = 0, len = 0;
284 unsigned int md_len = 0;
285 int ret = 0;
286
287 /* Limited to SHA-1 and SHA-2 hashes presently */
288 if (okey == NULL || okeylen == 0)
289 return 0;
290
291 md = EVP_MD_CTX_new();
292 if (md == NULL) {
293 ERR_raise(ERR_LIB_PROV, PROV_R_MISSING_MESSAGE_DIGEST);
294 goto err;
295 }
296
297 mdsize = EVP_MD_get_size(evp_md);
298 if (mdsize <= 0 || mdsize < okeylen)
299 goto err;
300
301 if (!EVP_DigestInit_ex(md, evp_md, NULL))
302 goto err;
303
304 for (len = 0; len < KDF_SNMP_PASSWORD_HASH_AMOUNT - password_len; len += password_len) {
…lines 305–311 unchanged (7 lines)
312 || !EVP_DigestUpdate(md, digest, mdsize)
313 || !EVP_DigestUpdate(md, e_id, e_len)
314 || !EVP_DigestUpdate(md, digest, mdsize)
315 || !EVP_DigestFinal_ex(md, digest, &md_len))
316 goto err;
317
318 memcpy(okey, digest, okeylen);
319
320 ret = 1;
321
322err:
323 EVP_MD_CTX_free(md);
324 OPENSSL_cleanse(digest, EVP_MAX_MD_SIZE);
325 return ret;
326}
327

After

…lines 1–240 unchanged (240 lines)
241 { OSSL_FUNC_KDF_SET_CTX_PARAMS, (void (*)(void))kdf_snmpkdf_set_ctx_params },
242 { OSSL_FUNC_KDF_GETTABLE_CTX_PARAMS,
243 (void (*)(void))kdf_snmpkdf_gettable_ctx_params },
244 { OSSL_FUNC_KDF_GET_CTX_PARAMS, (void (*)(void))kdf_snmpkdf_get_ctx_params },
245 { 0, NULL }
246};
247
248/*
249 * SNMPKDF - In compliance with SP800-135 and RFC7860, calculate
250 * a master key using the engine ID and password.
251 *
252 * Denote engineLength and passwordlen to be the lengths (in bytes) of an
253 * snmpEngineID and a password, respectively.
…lines 254–261 unchanged (8 lines)
262 *
263 * Let Shared_key to be the key that the user shares with the authoritative
264 * SNMP engine with ID snmpEngineID. The Shared_key is generated as follows:
265 *
266 * Shared_key = SHA-1(Derived_password || snmpEngineID || Derived_password).
267 *
268 * Input:
269 * e_id - engine ID(eid)
270 * e_len - engineID length
271 * password - password
272 * password_len - password length
273 * okey - pointer to key output, FIPS testing limited to SHA-1.
274 * keylen - key length
275 * Output:
276 * okey - filled with derived key
277 * return - 1 on pass, 0 fail
278 */
279static int SNMPKDF(const EVP_MD *evp_md,
280 const unsigned char *e_id, size_t e_len,
281 unsigned char *password, size_t password_len,
282 unsigned char *okey, size_t keylen)
283{
284 EVP_MD_CTX *md = NULL;
285 unsigned char digest[EVP_MAX_MD_SIZE];
286 size_t mdsize = 0, len = 0;
287 unsigned int md_len = 0;
288 int ret = 0;
289
290 /* Limited to SHA-1 and SHA-2 hashes presently */
291 if (okey == NULL || keylen == 0)
292 return 0;
293
294 md = EVP_MD_CTX_new();
295 if (md == NULL) {
296 ERR_raise(ERR_LIB_PROV, PROV_R_MISSING_MESSAGE_DIGEST);
297 goto err;
298 }
299
300 mdsize = EVP_MD_get_size(evp_md);
301 if (mdsize <= 0 || mdsize > keylen)
302 goto err;
303
304 if (!EVP_DigestInit_ex(md, evp_md, NULL))
305 goto err;
306
307 for (len = 0; len < KDF_SNMP_PASSWORD_HASH_AMOUNT - password_len; len += password_len) {
…lines 308–314 unchanged (7 lines)
315 || !EVP_DigestUpdate(md, digest, mdsize)
316 || !EVP_DigestUpdate(md, e_id, e_len)
317 || !EVP_DigestUpdate(md, digest, mdsize)
318 || !EVP_DigestFinal_ex(md, digest, &md_len))
319 goto err;
320
321 memcpy(okey, digest, md_len);
322
323 ret = 1;
324
325err:
326 EVP_MD_CTX_free(md);
327 OPENSSL_cleanse(digest, EVP_MAX_MD_SIZE);
328 return ret;
329}
330

Before

translation_unit
comment "/*\n * Copyright 2025 The OpenSSL Project Authors. All Rights"...
preproc_include
#include "#include"
system_lib_string "<stdlib.h>"
preproc_include
#include "#include"
system_lib_string "<stdarg.h>"
preproc_include
#include "#include"
system_lib_string "<string.h>"
preproc_include
#include "#include"
system_lib_string "<openssl/evp.h>"
preproc_include
#include "#include"
system_lib_string "<openssl/kdf.h>"
preproc_include
#include "#include"
system_lib_string "<openssl/sha.h>"
preproc_include
#include "#include"
system_lib_string "<openssl/core_names.h>"
preproc_include
#include "#include"
system_lib_string "<openssl/proverr.h>"
preproc_include
#include "#include"
string_literal
" "\""
string_content "internal/cryptlib.h"
" "\""
preproc_include
#include "#include"
string_literal
" "\""
string_content "internal/numbers.h"
" "\""
preproc_include
#include "#include"
string_literal
" "\""
string_content "crypto/evp.h"
" "\""
preproc_include
#include "#include"
string_literal
" "\""
string_content "prov/provider_ctx.h"
" "\""
preproc_include
#include "#include"
string_literal
" "\""
string_content "prov/providercommon.h"
" "\""
preproc_include
#include "#include"
string_literal
" "\""
string_content "prov/implementations.h"
" "\""
preproc_include
#include "#include"
string_literal
" "\""
string_content "prov/provider_util.h"
" "\""
preproc_include
#include "#include"
string_literal
" "\""
string_content "providers/implementations/kdfs/snmpkdf.inc"
" "\""
preproc_def
#define "#define"
identifier "KDF_SNMP_PASSWORD_HASH_AMOUNT"
preproc_arg "(1024 * 1024)"
preproc_def
#define "#define"
identifier "KDF_SNMP_MIN_PASSWORD_LEN"
preproc_arg "8"
comment "/* See RFC 3414, Appendix A.2.2 */"
comment "/* See NIST SP800-135 Section 6.8 */"
declaration
storage_class_specifier
static "static"
type_identifier "OSSL_FUNC_kdf_newctx_fn"
identifier "kdf_snmpkdf_new"
; ";"
declaration
storage_class_specifier
static "static"
type_identifier "OSSL_FUNC_kdf_dupctx_fn"
identifier "kdf_snmpkdf_dup"
; ";"
declaration
storage_class_specifier
static "static"
type_identifier "OSSL_FUNC_kdf_freectx_fn"
identifier "kdf_snmpkdf_free"
; ";"
declaration
storage_class_specifier
static "static"
type_identifier "OSSL_FUNC_kdf_reset_fn"
identifier "kdf_snmpkdf_reset"
; ";"
declaration
storage_class_specifier
static "static"
type_identifier "OSSL_FUNC_kdf_derive_fn"
identifier "kdf_snmpkdf_derive"
; ";"
declaration
storage_class_specifier
static "static"
type_identifier "OSSL_FUNC_kdf_settable_ctx_params_fn"
identifier "kdf_snmpkdf_settable_ctx_params"
; ";"
declaration
storage_class_specifier
static "static"
type_identifier "OSSL_FUNC_kdf_set_ctx_params_fn"
identifier "kdf_snmpkdf_set_ctx_params"
; ";"
declaration
storage_class_specifier
static "static"
type_identifier "OSSL_FUNC_kdf_gettable_ctx_params_fn"
identifier "kdf_snmpkdf_gettable_ctx_params"
; ";"
declaration
storage_class_specifier
static "static"
type_identifier "OSSL_FUNC_kdf_get_ctx_params_fn"
identifier "kdf_snmpkdf_get_ctx_params"
; ";"
declaration (+55 nodes collapsed)
type_definition (+44 nodes collapsed)
function_definition (+83 nodes collapsed)
function_definition (+185 nodes collapsed)
function_definition (+62 nodes collapsed)
function_definition (+118 nodes collapsed)
function_definition (+90 nodes collapsed)
function_definition (+226 nodes collapsed)
function_definition (+337 nodes collapsed)
function_definition (+35 nodes collapsed)
function_definition (+107 nodes collapsed)
function_definition (+134 nodes collapsed)
function_definition (+35 nodes collapsed)
declaration (+228 nodes collapsed)
comment "/*\n * SNMPKDF - In compliance with SP800-135 and RFC7860, ca"...
function_definition
storage_class_specifier
static "static"
primitive_type "int"
function_declarator
identifier "SNMPKDF"
parameter_list
( "("
parameter_declaration
type_qualifier
const "const"
type_identifier "EVP_MD"
pointer_declarator
* "*"
identifier "evp_md"
, ","
parameter_declaration
type_qualifier
const "const"
sized_type_specifier
unsigned "unsigned"
primitive_type "char"
pointer_declarator
* "*"
identifier "e_id"
, ","
parameter_declaration
primitive_type "size_t"
identifier "e_len"
, ","
parameter_declaration
sized_type_specifier
unsigned "unsigned"
primitive_type "char"
pointer_declarator
* "*"
identifier "password"
, ","
parameter_declaration
primitive_type "size_t"
identifier "password_len"
, ","
parameter_declaration
sized_type_specifier
unsigned "unsigned"
primitive_type "char"
pointer_declarator
* "*"
identifier "okey"
, ","
parameter_declaration
primitive_type "size_t"
identifier "okeylen"
) ")"
compound_statement
{ "{"
declaration
type_identifier "EVP_MD_CTX"
init_declarator
pointer_declarator
* "*"
identifier "md"
= "="
null
NULL "NULL"
; ";"
declaration
sized_type_specifier
unsigned "unsigned"
primitive_type "char"
array_declarator
identifier "digest"
[ "["
identifier "EVP_MAX_MD_SIZE"
] "]"
; ";"
declaration
primitive_type "size_t"
init_declarator
identifier "mdsize"
= "="
number_literal "0"
, ","
init_declarator
identifier "len"
= "="
number_literal "0"
; ";"
declaration
sized_type_specifier
unsigned "unsigned"
primitive_type "int"
init_declarator
identifier "md_len"
= "="
number_literal "0"
; ";"
declaration
primitive_type "int"
init_declarator
identifier "ret"
= "="
number_literal "0"
; ";"
comment "/* Limited to SHA-1 and SHA-2 hashes presently */"
if_statement
if "if"
parenthesized_expression
( "("
binary_expression
binary_expression
identifier "okey"
== "=="
null
NULL "NULL"
|| "||"
binary_expression
identifier "okeylen"
== "=="
number_literal "0"
) ")"
return_statement
return "return"
number_literal "0"
; ";"
expression_statement
assignment_expression
identifier "md"
= "="
call_expression
identifier "EVP_MD_CTX_new"
argument_list
( "("
) ")"
; ";"
if_statement (+27 nodes collapsed)
expression_statement
assignment_expression
identifier "mdsize"
= "="
call_expression
identifier "EVP_MD_get_size"
argument_list
( "("
identifier "evp_md"
) ")"
; ";"
if_statement
if "if"
parenthesized_expression
( "("
binary_expression
binary_expression
identifier "mdsize"
<= "<="
number_literal "0"
|| "||"
binary_expression
identifier "mdsize"
< "<"
identifier "okeylen"
) ")"
goto_statement
goto "goto"
statement_identifier "err"
; ";"
if_statement (+22 nodes collapsed)
for_statement (+45 nodes collapsed)
if_statement (+113 nodes collapsed)
expression_statement
call_expression
identifier "memcpy"
argument_list
( "("
identifier "okey"
, ","
identifier "digest"
, ","
identifier "okeylen"
) ")"
; ";"
expression_statement
assignment_expression
identifier "ret"
= "="
number_literal "1"
; ";"
labeled_statement
statement_identifier "err"
: ":"
expression_statement
call_expression
identifier "EVP_MD_CTX_free"
argument_list
( "("
identifier "md"
) ")"
; ";"
expression_statement
call_expression
identifier "OPENSSL_cleanse"
argument_list
( "("
identifier "digest"
, ","
identifier "EVP_MAX_MD_SIZE"
) ")"
; ";"
return_statement
return "return"
identifier "ret"
; ";"
} "}"

After

translation_unit
comment "/*\n * Copyright 2025 The OpenSSL Project Authors. All Rights"...
preproc_include
#include "#include"
system_lib_string "<stdlib.h>"
preproc_include
#include "#include"
system_lib_string "<stdarg.h>"
preproc_include
#include "#include"
system_lib_string "<string.h>"
preproc_include
#include "#include"
system_lib_string "<openssl/evp.h>"
preproc_include
#include "#include"
system_lib_string "<openssl/kdf.h>"
preproc_include
#include "#include"
system_lib_string "<openssl/sha.h>"
preproc_include
#include "#include"
system_lib_string "<openssl/core_names.h>"
preproc_include
#include "#include"
system_lib_string "<openssl/proverr.h>"
preproc_include
#include "#include"
string_literal
" "\""
string_content "internal/cryptlib.h"
" "\""
preproc_include
#include "#include"
string_literal
" "\""
string_content "internal/numbers.h"
" "\""
preproc_include
#include "#include"
string_literal
" "\""
string_content "crypto/evp.h"
" "\""
preproc_include
#include "#include"
string_literal
" "\""
string_content "prov/provider_ctx.h"
" "\""
preproc_include
#include "#include"
string_literal
" "\""
string_content "prov/providercommon.h"
" "\""
preproc_include
#include "#include"
string_literal
" "\""
string_content "prov/implementations.h"
" "\""
preproc_include
#include "#include"
string_literal
" "\""
string_content "prov/provider_util.h"
" "\""
preproc_include
#include "#include"
string_literal
" "\""
string_content "providers/implementations/kdfs/snmpkdf.inc"
" "\""
preproc_def
#define "#define"
identifier "KDF_SNMP_PASSWORD_HASH_AMOUNT"
preproc_arg "(1024 * 1024)"
preproc_def
#define "#define"
identifier "KDF_SNMP_MIN_PASSWORD_LEN"
preproc_arg "8"
comment "/* See RFC 3414, Appendix A.2.2 */"
comment "/* See NIST SP800-135 Section 6.8 */"
declaration
storage_class_specifier
static "static"
type_identifier "OSSL_FUNC_kdf_newctx_fn"
identifier "kdf_snmpkdf_new"
; ";"
declaration
storage_class_specifier
static "static"
type_identifier "OSSL_FUNC_kdf_dupctx_fn"
identifier "kdf_snmpkdf_dup"
; ";"
declaration
storage_class_specifier
static "static"
type_identifier "OSSL_FUNC_kdf_freectx_fn"
identifier "kdf_snmpkdf_free"
; ";"
declaration
storage_class_specifier
static "static"
type_identifier "OSSL_FUNC_kdf_reset_fn"
identifier "kdf_snmpkdf_reset"
; ";"
declaration
storage_class_specifier
static "static"
type_identifier "OSSL_FUNC_kdf_derive_fn"
identifier "kdf_snmpkdf_derive"
; ";"
declaration
storage_class_specifier
static "static"
type_identifier "OSSL_FUNC_kdf_settable_ctx_params_fn"
identifier "kdf_snmpkdf_settable_ctx_params"
; ";"
declaration
storage_class_specifier
static "static"
type_identifier "OSSL_FUNC_kdf_set_ctx_params_fn"
identifier "kdf_snmpkdf_set_ctx_params"
; ";"
declaration
storage_class_specifier
static "static"
type_identifier "OSSL_FUNC_kdf_gettable_ctx_params_fn"
identifier "kdf_snmpkdf_gettable_ctx_params"
; ";"
declaration
storage_class_specifier
static "static"
type_identifier "OSSL_FUNC_kdf_get_ctx_params_fn"
identifier "kdf_snmpkdf_get_ctx_params"
; ";"
declaration (+55 nodes collapsed)
type_definition (+44 nodes collapsed)
function_definition (+83 nodes collapsed)
function_definition (+185 nodes collapsed)
function_definition (+62 nodes collapsed)
function_definition (+118 nodes collapsed)
function_definition (+90 nodes collapsed)
function_definition (+226 nodes collapsed)
function_definition (+337 nodes collapsed)
function_definition (+35 nodes collapsed)
function_definition (+107 nodes collapsed)
function_definition (+134 nodes collapsed)
function_definition (+35 nodes collapsed)
declaration (+228 nodes collapsed)
comment "/*\n * SNMPKDF - In compliance with SP800-135 and RFC7860, ca"...
function_definition
storage_class_specifier
static "static"
primitive_type "int"
function_declarator
identifier "SNMPKDF"
parameter_list
( "("
parameter_declaration
type_qualifier
const "const"
type_identifier "EVP_MD"
pointer_declarator
* "*"
identifier "evp_md"
, ","
parameter_declaration
type_qualifier
const "const"
sized_type_specifier
unsigned "unsigned"
primitive_type "char"
pointer_declarator
* "*"
identifier "e_id"
, ","
parameter_declaration
primitive_type "size_t"
identifier "e_len"
, ","
parameter_declaration
sized_type_specifier
unsigned "unsigned"
primitive_type "char"
pointer_declarator
* "*"
identifier "password"
, ","
parameter_declaration
primitive_type "size_t"
identifier "password_len"
, ","
parameter_declaration
sized_type_specifier
unsigned "unsigned"
primitive_type "char"
pointer_declarator
* "*"
identifier "okey"
, ","
parameter_declaration
primitive_type "size_t"
identifier "keylen"
) ")"
compound_statement
{ "{"
declaration
type_identifier "EVP_MD_CTX"
init_declarator
pointer_declarator
* "*"
identifier "md"
= "="
null
NULL "NULL"
; ";"
declaration
sized_type_specifier
unsigned "unsigned"
primitive_type "char"
array_declarator
identifier "digest"
[ "["
identifier "EVP_MAX_MD_SIZE"
] "]"
; ";"
declaration
primitive_type "size_t"
init_declarator
identifier "mdsize"
= "="
number_literal "0"
, ","
init_declarator
identifier "len"
= "="
number_literal "0"
; ";"
declaration
sized_type_specifier
unsigned "unsigned"
primitive_type "int"
init_declarator
identifier "md_len"
= "="
number_literal "0"
; ";"
declaration
primitive_type "int"
init_declarator
identifier "ret"
= "="
number_literal "0"
; ";"
comment "/* Limited to SHA-1 and SHA-2 hashes presently */"
if_statement
if "if"
parenthesized_expression
( "("
binary_expression
binary_expression
identifier "okey"
== "=="
null
NULL "NULL"
|| "||"
binary_expression
identifier "keylen"
== "=="
number_literal "0"
) ")"
return_statement
return "return"
number_literal "0"
; ";"
expression_statement
assignment_expression
identifier "md"
= "="
call_expression
identifier "EVP_MD_CTX_new"
argument_list
( "("
) ")"
; ";"
if_statement (+27 nodes collapsed)
expression_statement
assignment_expression
identifier "mdsize"
= "="
call_expression
identifier "EVP_MD_get_size"
argument_list
( "("
identifier "evp_md"
) ")"
; ";"
if_statement
if "if"
parenthesized_expression
( "("
binary_expression
binary_expression
identifier "mdsize"
<= "<="
number_literal "0"
|| "||"
binary_expression
identifier "mdsize"
> ">"
identifier "keylen"
) ")"
goto_statement
goto "goto"
statement_identifier "err"
; ";"
if_statement (+22 nodes collapsed)
for_statement (+45 nodes collapsed)
if_statement (+113 nodes collapsed)
expression_statement
call_expression
identifier "memcpy"
argument_list
( "("
identifier "okey"
, ","
identifier "digest"
, ","
identifier "md_len"
) ")"
; ";"
expression_statement
assignment_expression
identifier "ret"
= "="
number_literal "1"
; ";"
labeled_statement
statement_identifier "err"
: ":"
expression_statement
call_expression
identifier "EVP_MD_CTX_free"
argument_list
( "("
identifier "md"
) ")"
; ";"
expression_statement
call_expression
identifier "OPENSSL_cleanse"
argument_list
( "("
identifier "digest"
, ","
identifier "EVP_MAX_MD_SIZE"
) ")"
; ";"
return_statement
return "return"
identifier "ret"
; ";"
} "}"