crypto: Migrate unexportable_key to new hash APIs
MERGEDcrypto
2025. 5. 9.
minsubb13

/crypto의 unexportable_key 파일의 crypto/sha2 API를 새로운 crypto/hash interface로 migrate하였습니다.
문제 설명
- issue url: https://crbug.com/372283556
- 위 이슈에서는 old API를 new API로 migrate 하기를 원하고 있습니다.
- /crypto 디렉토리의 unexportable_key_software_unsecure.cc 와
unexportable_key_win.cc 두 파일은 오래된 hash API를 사용하고 있었습니다. 이를 새로운 API로 변경하고자하는 이슈입니다.
해결 내용
오래된 API인 "crypto/sha2.h" 와 새로운 API인 "crypto/hash.h" 소스 코드를 분석하여 대체할 수 있는 함수를 찾았습니다.
- "crypto/sha2.h" 에는
SHA256Hash
함수가, "crypto/hash.h" 에는Sha256
함수가 매칭되어 있습니다.
- "crypto/sha2.h" 에는
이를 교체하는 작업을 수행하였습니다.
--- a/crypto/unexportable_key_software_unsecure.cc +++ b/crypto/unexportable_key_software_unsecure.cc - std::array<uint8_t, kSHA256Length> digest = SHA256Hash(data); + std::array<uint8_t, hash::kSha256Size> digest = crypto::hash::Sha256(data); - std::array<uint8_t, kSHA256Length> digest = SHA256Hash(data); + std::array<uint8_t, hash::kSha256Size> digest = crypto::hash::Sha256(data);
(unexportable_key_win도 동일)
테스트 방법
unexportable_key_win.cc 파일은 windows 운영체제 전용 파일이라 macOS를 사용하고 있는 저는 빌드조차 안되는 파일입니다. 따라서 이 파일의 테스트는 gerrit의 dry-run에 맡기기로 하였습니다. 반면, unexportable_key_software_unsecure.cc 파일은 정상 빌드가 가능하여 이를 통해 테스트를 수행하였습니다. 수정 사항을 테스트하기 위하여 unittest 빌드를 진행하여 unittest를 진행해 테스트를 수행하였습니다.
- unexportable_key unittest는 crypto_unittests에 속해있고, 이는
autoninja -C out/Default crypto_unittests
를 통해 빌드할 수 있습니다. - 빌드를 수행하면 out/Default에 crypto_unittests 파일이 생성됩니다.
out/Default/crypto_unittests --gtest_list_tests
를 통해 crytpo_unittests의 테스트 리스트를 볼 수 있습니다.- 다음 명령어를 통해 테스트를 실행시킬 수 있습니다.
# 전체 unittest 실행 out/Default/crypto_unittests --single-process-tests # 특정 unittest 실행 out/Default/crypto_unittests --gtest_filter="*SecureHashTest*" --single-process-tests
배운 점
- 간단한 코드 작업이었지만 코드 수정을 실제로 체험해보면서 많이 배울 수 있었다.
- unittest를 빌드해보고 실행해보는 경험을 할 수 있었다.
- gerrit에 조금더 익숙해질 수 있었다.
- 리뷰어분이 생각보다 친절하게 comment를 남겨줘서 놀랬다. 초심자의 행운인가?
참고 자료
- issue url: https://crbug.com/372283556
- gerrit url: https://crrev.com/c/6518080
- run gtest locally docs: https://chromium.googlesource.com/chromium/src/+/main/docs/testing/testing_in_chromium.md#Run-gtest-locally