@@ -375,7 +375,7 @@ bool totp_config_file_load(PluginState* const plugin_state) {
375375 break ;
376376 }
377377
378- plugin_state -> crypto_version = tmp_uint32 ;
378+ plugin_state -> crypto_settings . crypto_version = tmp_uint32 ;
379379
380380 if (!flipper_format_rewind (fff_data_file )) {
381381 break ;
@@ -388,7 +388,7 @@ bool totp_config_file_load(PluginState* const plugin_state) {
388388 break ;
389389 }
390390
391- plugin_state -> crypto_key_slot = tmp_uint32 ;
391+ plugin_state -> crypto_settings . crypto_key_slot = tmp_uint32 ;
392392
393393 if (!flipper_format_rewind (fff_data_file )) {
394394 break ;
@@ -397,7 +397,7 @@ bool totp_config_file_load(PluginState* const plugin_state) {
397397 if (!flipper_format_read_hex (
398398 fff_data_file ,
399399 TOTP_CONFIG_KEY_BASE_IV ,
400- & plugin_state -> base_iv [0 ],
400+ & plugin_state -> crypto_settings . base_iv [0 ],
401401 CRYPTO_IV_LENGTH )) {
402402 FURI_LOG_D (LOGGING_TAG , "Missing base IV" );
403403 }
@@ -410,22 +410,23 @@ bool totp_config_file_load(PluginState* const plugin_state) {
410410 if (flipper_format_get_value_count (
411411 fff_data_file , TOTP_CONFIG_KEY_CRYPTO_VERIFY , & crypto_size ) &&
412412 crypto_size > 0 ) {
413- plugin_state -> crypto_verify_data = malloc (sizeof (uint8_t ) * crypto_size );
414- furi_check (plugin_state -> crypto_verify_data != NULL );
415- plugin_state -> crypto_verify_data_length = crypto_size ;
413+ plugin_state -> crypto_settings .crypto_verify_data =
414+ malloc (sizeof (uint8_t ) * crypto_size );
415+ furi_check (plugin_state -> crypto_settings .crypto_verify_data != NULL );
416+ plugin_state -> crypto_settings .crypto_verify_data_length = crypto_size ;
416417 if (!flipper_format_read_hex (
417418 fff_data_file ,
418419 TOTP_CONFIG_KEY_CRYPTO_VERIFY ,
419- plugin_state -> crypto_verify_data ,
420+ plugin_state -> crypto_settings . crypto_verify_data ,
420421 crypto_size )) {
421422 FURI_LOG_D (LOGGING_TAG , "Missing crypto verify token" );
422- free (plugin_state -> crypto_verify_data );
423- plugin_state -> crypto_verify_data = NULL ;
424- plugin_state -> crypto_verify_data_length = 0 ;
423+ free (plugin_state -> crypto_settings . crypto_verify_data );
424+ plugin_state -> crypto_settings . crypto_verify_data = NULL ;
425+ plugin_state -> crypto_settings . crypto_verify_data_length = 0 ;
425426 }
426427 } else {
427- plugin_state -> crypto_verify_data = NULL ;
428- plugin_state -> crypto_verify_data_length = 0 ;
428+ plugin_state -> crypto_settings . crypto_verify_data = NULL ;
429+ plugin_state -> crypto_settings . crypto_verify_data_length = 0 ;
429430 }
430431
431432 if (!flipper_format_rewind (fff_data_file )) {
@@ -443,8 +444,11 @@ bool totp_config_file_load(PluginState* const plugin_state) {
443444 }
444445
445446 if (!flipper_format_read_bool (
446- fff_data_file , TOTP_CONFIG_KEY_PINSET , & plugin_state -> pin_set , 1 )) {
447- plugin_state -> pin_set = true;
447+ fff_data_file ,
448+ TOTP_CONFIG_KEY_PINSET ,
449+ & plugin_state -> crypto_settings .pin_required ,
450+ 1 )) {
451+ plugin_state -> crypto_settings .pin_required = true;
448452 }
449453
450454 if (!flipper_format_rewind (fff_data_file )) {
@@ -498,9 +502,7 @@ bool totp_config_file_load(PluginState* const plugin_state) {
498502 totp_token_info_iterator_alloc (
499503 storage ,
500504 plugin_state -> config_file_context -> config_file ,
501- plugin_state -> iv ,
502- plugin_state -> crypto_version ,
503- plugin_state -> crypto_key_slot );
505+ & plugin_state -> crypto_settings );
504506 result = true;
505507 } while (false);
506508
@@ -513,33 +515,39 @@ bool totp_config_file_update_crypto_signatures(const PluginState* plugin_state)
513515 flipper_format_rewind (config_file );
514516 bool update_result = false;
515517 do {
516- uint32_t tmp_uint32 = plugin_state -> crypto_version ;
518+ uint32_t tmp_uint32 = plugin_state -> crypto_settings . crypto_version ;
517519 if (!flipper_format_insert_or_update_uint32 (
518520 config_file , TOTP_CONFIG_KEY_CRYPTO_VERSION , & tmp_uint32 , 1 )) {
519521 break ;
520522 }
521523
522- tmp_uint32 = plugin_state -> crypto_key_slot ;
524+ tmp_uint32 = plugin_state -> crypto_settings . crypto_key_slot ;
523525 if (!flipper_format_insert_or_update_uint32 (
524526 config_file , TOTP_CONFIG_KEY_CRYPTO_KEY_SLOT , & tmp_uint32 , 1 )) {
525527 break ;
526528 }
527529
528530 if (!flipper_format_insert_or_update_hex (
529- config_file , TOTP_CONFIG_KEY_BASE_IV , plugin_state -> base_iv , CRYPTO_IV_LENGTH )) {
531+ config_file ,
532+ TOTP_CONFIG_KEY_BASE_IV ,
533+ plugin_state -> crypto_settings .base_iv ,
534+ CRYPTO_IV_LENGTH )) {
530535 break ;
531536 }
532537
533538 if (!flipper_format_insert_or_update_hex (
534539 config_file ,
535540 TOTP_CONFIG_KEY_CRYPTO_VERIFY ,
536- plugin_state -> crypto_verify_data ,
537- plugin_state -> crypto_verify_data_length )) {
541+ plugin_state -> crypto_settings . crypto_verify_data ,
542+ plugin_state -> crypto_settings . crypto_verify_data_length )) {
538543 break ;
539544 }
540545
541546 if (!flipper_format_insert_or_update_bool (
542- config_file , TOTP_CONFIG_KEY_PINSET , & plugin_state -> pin_set , 1 )) {
547+ config_file ,
548+ TOTP_CONFIG_KEY_PINSET ,
549+ & plugin_state -> crypto_settings .pin_required ,
550+ 1 )) {
543551 break ;
544552 }
545553
@@ -581,24 +589,20 @@ bool totp_config_file_update_encryption(
581589 return false;
582590 }
583591
584- uint8_t old_iv [CRYPTO_IV_LENGTH ];
585- memcpy (& old_iv [0 ], & plugin_state -> iv [0 ], CRYPTO_IV_LENGTH );
586-
587- uint8_t old_crypto_key_slot = plugin_state -> crypto_key_slot ;
588- uint8_t old_crypto_version = plugin_state -> crypto_version ;
592+ CryptoSettings old_crypto_settings = plugin_state -> crypto_settings ;
589593
590- memset (& plugin_state -> iv [0 ], 0 , CRYPTO_IV_LENGTH );
591- memset (& plugin_state -> base_iv [0 ], 0 , CRYPTO_IV_LENGTH );
592- if (plugin_state -> crypto_verify_data != NULL ) {
593- free (plugin_state -> crypto_verify_data );
594- plugin_state -> crypto_verify_data = NULL ;
594+ memset (& plugin_state -> crypto_settings . iv [0 ], 0 , CRYPTO_IV_LENGTH );
595+ memset (& plugin_state -> crypto_settings . base_iv [0 ], 0 , CRYPTO_IV_LENGTH );
596+ if (plugin_state -> crypto_settings . crypto_verify_data != NULL ) {
597+ free (plugin_state -> crypto_settings . crypto_verify_data );
598+ plugin_state -> crypto_settings . crypto_verify_data = NULL ;
595599 }
596600
597- plugin_state -> crypto_key_slot = new_crypto_key_slot ;
598- plugin_state -> crypto_version = CRYPTO_LATEST_VERSION ;
601+ plugin_state -> crypto_settings . crypto_key_slot = new_crypto_key_slot ;
602+ plugin_state -> crypto_settings . crypto_version = CRYPTO_LATEST_VERSION ;
599603
600- CryptoSeedIVResult seed_result =
601- totp_crypto_seed_iv ( plugin_state , new_pin_length > 0 ? new_pin : NULL , new_pin_length );
604+ CryptoSeedIVResult seed_result = totp_crypto_seed_iv (
605+ & plugin_state -> crypto_settings , new_pin_length > 0 ? new_pin : NULL , new_pin_length );
602606 if (seed_result & CryptoSeedIVResultFlagSuccess &&
603607 seed_result & CryptoSeedIVResultFlagNewCryptoVerifyData &&
604608 !totp_config_file_update_crypto_signatures (plugin_state )) {
@@ -649,21 +653,14 @@ bool totp_config_file_update_encryption(
649653
650654 size_t plain_token_length ;
651655 uint8_t * plain_token = totp_crypto_decrypt (
652- encrypted_token ,
653- secret_bytes_count ,
654- & old_iv [0 ],
655- old_crypto_version ,
656- old_crypto_key_slot ,
657- & plain_token_length );
656+ encrypted_token , secret_bytes_count , & old_crypto_settings , & plain_token_length );
658657
659658 free (encrypted_token );
660659 size_t encrypted_token_length ;
661660 encrypted_token = totp_crypto_encrypt (
662661 plain_token ,
663662 plain_token_length ,
664- & plugin_state -> iv [0 ],
665- plugin_state -> crypto_version ,
666- plugin_state -> crypto_key_slot ,
663+ & plugin_state -> crypto_settings ,
667664 & encrypted_token_length );
668665
669666 memset_s (plain_token , plain_token_length , 0 , plain_token_length );
@@ -700,12 +697,12 @@ bool totp_config_file_ensure_latest_encryption(
700697 const uint8_t * pin ,
701698 uint8_t pin_length ) {
702699 bool result = true;
703- if (plugin_state -> crypto_version < CRYPTO_LATEST_VERSION ) {
700+ if (plugin_state -> crypto_settings . crypto_version < CRYPTO_LATEST_VERSION ) {
704701 FURI_LOG_I (LOGGING_TAG , "Migration to crypto v%d is needed" , CRYPTO_LATEST_VERSION );
705702 char * backup_path = totp_config_file_backup (plugin_state );
706703 if (backup_path != NULL ) {
707704 free (backup_path );
708- uint8_t crypto_key_slot = plugin_state -> crypto_key_slot ;
705+ uint8_t crypto_key_slot = plugin_state -> crypto_settings . crypto_key_slot ;
709706 if (!totp_crypto_check_key_slot (crypto_key_slot )) {
710707 crypto_key_slot = DEFAULT_CRYPTO_KEY_SLOT ;
711708 }
0 commit comments