Test that overly large Diffie-Hellman keys are rejected

Add a test case to ensure `mbedtls_mpi_exp_mod` fails when using a key size
larger than MBEDTLS_MPI_MAX_SIZE.
Add a test case to ensure that Diffie-Hellman operations fail when using a key
size larger than MBEDTLS_MPI_MAX_SIZE.

Signed-off-by: Chris Jones <christopher.jones@arm.com>
This commit is contained in:
Chris Jones 2020-11-26 11:21:53 +00:00
parent 8b1f65ea00
commit 8c650f985d
2 changed files with 9 additions and 3 deletions

View File

@ -19,10 +19,13 @@ dhm_do_dhm:10:"3":10:"5":MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED
Diffie-Hellman zero modulus
dhm_do_dhm:10:"0":10:"5":MBEDTLS_ERR_DHM_BAD_INPUT_DATA
Diffie-Hellman load parameters from file
Diffie-Hellman huge modulus
dhm_do_dhm:16:"50000000000000000000000000000000000000000000000000000000100014e4c3111300f060355040a13086f53534c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000052b810400224ee06ec30e5753333958e280a8000000809539c2885280afd66aab21ddb8d31c6e58b8cae8b2698ef341ad29c3b45f75a7476fd5192955699a533b20b4661660341e00000040000000160000000000001604149d316d202449023f2bcb78b519bc7fffc9cbfb357c316e0603cdcdcdcd0ba34677b8b3be2c3633023100fdbfff7b67df9d7b7f7f00476fd5192955699a533b20b4661660341e00000040000000160000000000001604149d316d202449023f2bcb78b519bc7fffc9cbfb357c316e0603cdcdcdcd0ba34677b8b3be2c3633023100fdbfff7b67df9d7b7f7f000000000001000400000000000000506f6c617253530000000000000000000000000000000000000000110000f6de000000000000000000000000000000000000000000000000000000000000000000000000000000000000004c323536193017060000004f000000000000000000000005000000000000000000000000001603030039020000350303cf02020244e8786d95de3d020202e101f2f34e75c8b70a610e44c1000000000000008400000d00a30000ff60010001000016000016030102660b00026200025f00025c30820258308201c1a003020102020900fbb04c2eab109b0c300d06092a864886f70d01010505003045310b3009060355040e130241553113301106035504080c0a536f6d654853746174653121301f060355040a0c18496e7465726e6574205769646769747320507479204c7464301e170d3134303732333230353034305a170d3137303432323230353034305a3045310b3009060355042e130241553113301106035574080c0a136f6d652d53746174653121301f06035504050c18496e7465726e6574205769646769747320507479204c746430819f300d06092a864886f70d010101050003818d003081890281816602ffffff9e000000000000020000bf1400000000000100000000000000feffef00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001e1e1e001e1e1e1e1e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000000000000000000000000040ffd0100010000160000000000000000000000000000ff00000008000000000000000000000000000000000000000000000000000000000000000000000100014e4c3111300f060355040a13086f53534c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000052b810400224ee06ec30e5753333958e280a8000000809539c2885280afd66aab21ddb8d31c6e58b8cae8b2698ef341ad29c3b45f75a7476fd5192955699a533b20b4661660341e00000040000000160000000000001604149d316d202449023f2bcb78b519bc7fffc9cbfb357c316e0603cdcdcdcd0ba34677b8b3be2c3633023100fdbfff7b67df9d7b7f7f00476fd5192955699a533b20b4661660341e00000040000000160000000000001604149d316d202449023f2bcb78b519bc7fffc9cbfb357c316e0603cdcdcdcd0ba34677b8b3be2c3633023100fdbfff7b67df9d7b7f7f000000000001000400000000000000506f6c617253530000000000000000000000000000000000000000110000f6de000000000000000000000000000000000000000000000000000000000000000000000000000000000000004c323536193017060000004f000000000000000000000005000000000000000000000000001603030039020000350303cf02020244e8786d95de3d020202e101f2f34e75c8b70a610e44c1000000000000008400000d00a30000ff60010001000016000016030102660b00026200025f00025c30820258308201c1a003020102020900fbb04c2eab109b0c300d06092a864886f70dc9784adc17e9e82f4cadccc1747090a92f8ca6840c0f404db671d219301706035504031310506f6c617253534c205465737420434130820122300d06092a864886f70d0101010500038201160303005b02000057030367c6699151ff4aec29cdbaabf2fbe3467cc254f81be8e78d765a2e63339fc99a2009fc99a2066310db7315864fc99a2066320db73058a3ff7f00001758e942d4abb2cdc64e9bb43ddc87c03db1b28d17e02cb23":10:"5":MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED+MBEDTLS_ERR_MPI_BAD_INPUT_DATA
Diffie-Hellman load parameters from file [#1]
dhm_file:"data_files/dhparams.pem":"9e35f430443a09904f3a39a979797d070df53378e79c2438bef4e761f3c714553328589b041c809be1d6c6b5f1fc9f47d3a25443188253a992a56818b37ba9de5a40d362e56eff0be5417474c125c199272c8fe41dea733df6f662c92ae76556e755d10c64e6a50968f67fc6ea73d0dca8569be2ba204e23580d8bca2f4975b3":"02":128
Diffie-Hellman load parameters from file
Diffie-Hellman load parameters from file [#2]
dhm_file:"data_files/dh.optlen.pem":"b3126aeaf47153c7d67f403030b292b5bd5a6c9eae1c137af34087fce2a36a578d70c5c560ad2bdb924c4a4dbee20a1671be7103ce87defa76908936803dbeca60c33e1289c1a03ac2c6c4e49405e5902fa0596a1cbaa895cc402d5213ed4a5f1f5ba8b5e1ed3da951a4c475afeb0ca660b7368c38c8e809f382d96ae19e60dc984e61cb42b5dfd723322acf327f9e413cda6400c15c5b2ea1fa34405d83982fba40e6d852da3d91019bf23511314254dc211a90833e5b1798ee52a78198c555644729ad92f060367c74ded37704adfc273a4a33fec821bd2ebd3bc051730e97a4dd14d2b766062592f5eec09d16bb50efebf2cc00dd3e0e3418e60ec84870f7":"800abfe7dc667aa17bcd7c04614bc221a65482ccc04b604602b0e131908a938ea11b48dc515dab7abcbb1e0c7fd66511edc0d86551b7632496e03df94357e1c4ea07a7ce1e381a2fcafdff5f5bf00df828806020e875c00926e4d011f88477a1b01927d73813cad4847c6396b9244621be2b00b63c659253318413443cd244215cd7fd4cbe796e82c6cf70f89cc0c528fb8e344809b31876e7ef739d5160d095c9684188b0c8755c7a468d47f56d6db9ea012924ecb0556fb71312a8d7c93bb2898ea08ee54eeb594548285f06a973cbbe2a0cb02e90f323fe045521f34c68354a6d3e95dbfff1eb64692edc0a44f3d3e408d0e479a541e779a6054259e2d854":256
Diffie-Hellman selftest

View File

@ -673,9 +673,12 @@ mbedtls_mpi_exp_mod:10:"-23":10:"13":10:"29":10:"":10:"5":0
Base test mbedtls_mpi_exp_mod #5 (Negative exponent)
mbedtls_mpi_exp_mod:10:"23":10:"-13":10:"29":10:"":10:"0":MBEDTLS_ERR_MPI_BAD_INPUT_DATA
Base test mbedtls_mpi_exp_mod #7 (Negative base + exponent)
Base test mbedtls_mpi_exp_mod #6 (Negative base + exponent)
mbedtls_mpi_exp_mod:10:"-23":10:"-13":10:"29":10:"":10:"0":MBEDTLS_ERR_MPI_BAD_INPUT_DATA
Base test mbedtls_mpi_exp_mod #7 (Huge exponent)
mbedtls_mpi_exp_mod:10:"23":16:"50000000000000000000000000000000000000000000000000000000100014e4c3111300f060355040a13086f53534c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000052b810400224ee06ec30e5753333958e280a8000000809539c2885280afd66aab21ddb8d31c6e58b8cae8b2698ef341ad29c3b45f75a7476fd5192955699a533b20b4661660341e00000040000000160000000000001604149d316d202449023f2bcb78b519bc7fffc9cbfb357c316e0603cdcdcdcd0ba34677b8b3be2c3633023100fdbfff7b67df9d7b7f7f00476fd5192955699a533b20b4661660341e00000040000000160000000000001604149d316d202449023f2bcb78b519bc7fffc9cbfb357c316e0603cdcdcdcd0ba34677b8b3be2c3633023100fdbfff7b67df9d7b7f7f000000000001000400000000000000506f6c617253530000000000000000000000000000000000000000110000f6de000000000000000000000000000000000000000000000000000000000000000000000000000000000000004c323536193017060000004f000000000000000000000005000000000000000000000000001603030039020000350303cf02020244e8786d95de3d020202e101f2f34e75c8b70a610e44c1000000000000008400000d00a30000ff60010001000016000016030102660b00026200025f00025c30820258308201c1a003020102020900fbb04c2eab109b0c300d06092a864886f70d01010505003045310b3009060355040e130241553113301106035504080c0a536f6d654853746174653121301f060355040a0c18496e7465726e6574205769646769747320507479204c7464301e170d3134303732333230353034305a170d3137303432323230353034305a3045310b3009060355042e130241553113301106035574080c0a136f6d652d53746174653121301f06035504050c18496e7465726e6574205769646769747320507479204c746430819f300d06092a864886f70d010101050003818d003081890281816602ffffff9e000000000000020000bf1400000000000100000000000000feffef00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001e1e1e001e1e1e1e1e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000000000000000000000000040ffd0100010000160000000000000000000000000000ff00000008000000000000000000000000000000000000000000000000000000000000000000000100014e4c3111300f060355040a13086f53534c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000052b810400224ee06ec30e5753333958e280a8000000809539c2885280afd66aab21ddb8d31c6e58b8cae8b2698ef341ad29c3b45f75a7476fd5192955699a533b20b4661660341e00000040000000160000000000001604149d316d202449023f2bcb78b519bc7fffc9cbfb357c316e0603cdcdcdcd0ba34677b8b3be2c3633023100fdbfff7b67df9d7b7f7f00476fd5192955699a533b20b4661660341e00000040000000160000000000001604149d316d202449023f2bcb78b519bc7fffc9cbfb357c316e0603cdcdcdcd0ba34677b8b3be2c3633023100fdbfff7b67df9d7b7f7f000000000001000400000000000000506f6c617253530000000000000000000000000000000000000000110000f6de000000000000000000000000000000000000000000000000000000000000000000000000000000000000004c323536193017060000004f000000000000000000000005000000000000000000000000001603030039020000350303cf02020244e8786d95de3d020202e101f2f34e75c8b70a610e44c1000000000000008400000d00a30000ff60010001000016000016030102660b00026200025f00025c30820258308201c1a003020102020900fbb04c2eab109b0c300d06092a864886f70dc9784adc17e9e82f4cadccc1747090a92f8ca6840c0f404db671d219301706035504031310506f6c617253534c205465737420434130820122300d06092a864886f70d0101010500038201160303005b02000057030367c6699151ff4aec29cdbaabf2fbe3467cc254f81be8e78d765a2e63339fc99a2009fc99a2066310db7315864fc99a2066320db73058a3ff7f00001758e942d4abb2cdc64e9bb43ddc87c03db1b28d17e02cb23":10:"29":10:"":10:"0":MBEDTLS_ERR_MPI_BAD_INPUT_DATA
Test mbedtls_mpi_exp_mod #1
mbedtls_mpi_exp_mod:10:"433019240910377478217373572959560109819648647016096560523769010881172869083338285573756574557395862965095016483867813043663981946477698466501451832407592327356331263124555137732393938242285782144928753919588632679050799198937132922145084847":10:"5781538327977828897150909166778407659250458379645823062042492461576758526757490910073628008613977550546382774775570888130029763571528699574717583228939535960234464230882573615930384979100379102915657483866755371559811718767760594919456971354184113721":10:"583137007797276923956891216216022144052044091311388601652961409557516421612874571554415606746479105795833145583959622117418531166391184939066520869800857530421873250114773204354963864729386957427276448683092491947566992077136553066273207777134303397724679138833126700957":10:"":10:"114597449276684355144920670007147953232659436380163461553186940113929777196018164149703566472936578890991049344459204199888254907113495794730452699842273939581048142004834330369483813876618772578869083248061616444392091693787039636316845512292127097865026290173004860736":0