1: %% 2: %% %CopyrightBegin% 3: %% 4: %% Copyright Ericsson AB 1999-2016. All Rights Reserved. 5: %% 6: %% Licensed under the Apache License, Version 2.0 (the "License"); 7: %% you may not use this file except in compliance with the License. 8: %% You may obtain a copy of the License at 9: %% 10: %% http://www.apache.org/licenses/LICENSE-2.0 11: %% 12: %% Unless required by applicable law or agreed to in writing, software 13: %% distributed under the License is distributed on an "AS IS" BASIS, 14: %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15: %% See the License for the specific language governing permissions and 16: %% limitations under the License. 17: %% 18: %% %CopyrightEnd% 19: %% 20: -module(crypto_SUITE). 21: 22: -include_lib("common_test/include/ct.hrl"). 23: 24: %% Note: This directive should only be used in test suites. 25: -compile(export_all). 26: %%-------------------------------------------------------------------- 27: %% Common Test interface functions ----------------------------------- 28: %%-------------------------------------------------------------------- 29: 30: suite() -> [{ct_hooks,[ts_install_cth]}]. 31: 32: all() -> 33: [app, 34: appup, 35: {group, md4}, 36: {group, md5}, 37: {group, ripemd160}, 38: {group, sha}, 39: {group, sha224}, 40: {group, sha256}, 41: {group, sha384}, 42: {group, sha512}, 43: {group, rsa}, 44: {group, dss}, 45: {group, ecdsa}, 46: {group, dh}, 47: {group, ecdh}, 48: {group, srp}, 49: {group, des_cbc}, 50: {group, des_cfb}, 51: {group, des3_cbc}, 52: {group, des3_cbf}, 53: {group, des3_cfb}, 54: {group, des_ede3}, 55: {group, blowfish_cbc}, 56: {group, blowfish_ecb}, 57: {group, blowfish_cfb64}, 58: {group, blowfish_ofb64}, 59: {group, aes_cbc128}, 60: {group, aes_cfb8}, 61: {group, aes_cfb128}, 62: {group, aes_cbc256}, 63: {group, aes_ecb}, 64: {group, aes_ige256}, 65: {group, rc2_cbc}, 66: {group, rc4}, 67: {group, aes_ctr}, 68: {group, aes_gcm}, 69: {group, chacha20_poly1305}, 70: {group, aes_cbc}, 71: mod_pow, 72: exor, 73: rand_uniform 74: ]. 75: 76: groups() -> 77: [{md4, [], [hash]}, 78: {md5, [], [hash, hmac]}, 79: {ripemd160, [], [hash]}, 80: {sha, [], [hash, hmac]}, 81: {sha224, [], [hash, hmac]}, 82: {sha256, [], [hash, hmac]}, 83: {sha384, [], [hash, hmac]}, 84: {sha512, [], [hash, hmac]}, 85: {rsa, [], [sign_verify, 86: public_encrypt 87: ]}, 88: {dss, [], [sign_verify]}, 89: {ecdsa, [], [sign_verify]}, 90: {dh, [], [generate_compute]}, 91: {ecdh, [], [compute, generate]}, 92: {srp, [], [generate_compute]}, 93: {des_cbc, [], [block]}, 94: {des_cfb, [], [block]}, 95: {des3_cbc,[], [block]}, 96: {des_ede3,[], [block]}, 97: {des3_cbf,[], [block]}, 98: {des3_cfb,[], [block]}, 99: {rc2_cbc,[], [block]}, 100: {aes_cbc128,[], [block]}, 101: {aes_cfb8,[], [block]}, 102: {aes_cfb128,[], [block]}, 103: {aes_cbc256,[], [block]}, 104: {aes_ecb,[], [block]}, 105: {aes_ige256,[], [block]}, 106: {blowfish_cbc, [], [block]}, 107: {blowfish_ecb, [], [block]}, 108: {blowfish_cfb64, [], [block]}, 109: {blowfish_ofb64,[], [block]}, 110: {rc4, [], [stream]}, 111: {aes_ctr, [], [stream]}, 112: {aes_gcm, [], [aead]}, 113: {chacha20_poly1305, [], [aead]}, 114: {aes_cbc, [], [block]} 115: ]. 116: 117: %%------------------------------------------------------------------- 118: init_per_suite(Config) -> 119: try crypto:start() of 120: ok -> 121: try crypto:strong_rand_bytes(1) of 122: _ -> 123: Config 124: catch error:low_entropy -> 125: %% We are testing on an OS with low entropy in its random 126: %% seed. So we have to seed it with a binary to get started. 127: 128: %% This is NOT how you want to do seeding, it is just here 129: %% to make the tests pass. Check your OS manual for how you 130: %% really want to seed. 131: {H,M,L} = erlang:now(), 132: Bin = <<H:24,M:20,L:20>>, 133: crypto:rand_seed(<< <<Bin/binary>> || _ <- lists:seq(1,16) >>), 134: Config 135: end 136: catch _:_ -> 137: {skip, "Crypto did not start"} 138: end. 139: 140: end_per_suite(_Config) -> 141: application:stop(crypto). 142: 143: %%------------------------------------------------------------------- 144: init_per_group(GroupName, Config) -> 145: case is_supported(GroupName) of 146: true -> 147: group_config(GroupName, Config); 148: false -> 149: {skip, "Group not supported"} 150: end. 151: 152: end_per_group(_GroupName, Config) -> 153: Config. 154: 155: init_per_testcase(info, Config) -> 156: Config; 157: init_per_testcase(_Name,Config) -> 158: Config. 159: 160: end_per_testcase(info, Config) -> 161: Config; 162: end_per_testcase(_Name,Config) -> 163: Config. 164: 165: %%-------------------------------------------------------------------- 166: %% Test Cases -------------------------------------------------------- 167: %%-------------------------------------------------------------------- 168: app() -> 169: [{doc, "Test that the crypto app file is ok"}]. 170: app(Config) when is_list(Config) -> 171: ok = ?t:app_test(crypto). 172: %%-------------------------------------------------------------------- 173: appup() -> 174: [{doc, "Test that the crypto appup file is ok"}]. 175: appup(Config) when is_list(Config) -> 176: ok = ?t:appup_test(crypto). 177: %%-------------------------------------------------------------------- 178: hash() -> 179: [{doc, "Test all different hash functions"}]. 180: hash(Config) when is_list(Config) -> 181: {Type, MsgsLE, Digests} = proplists:get_value(hash, Config), 182: Msgs = lazy_eval(MsgsLE), 183: [LongMsg | _] = lists:reverse(Msgs), 184: Inc = iolistify(LongMsg), 185: [IncrDigest | _] = lists:reverse(Digests), 186: hash(Type, Msgs, Digests), 187: hash(Type, lists:map(fun iolistify/1, Msgs), Digests), 188: hash_increment(Type, Inc, IncrDigest). 189: %%-------------------------------------------------------------------- 190: hmac() -> 191: [{doc, "Test all different hmac functions"}]. 192: hmac(Config) when is_list(Config) -> 193: {Type, Keys, DataLE, Expected} = proplists:get_value(hmac, Config), 194: Data = lazy_eval(DataLE), 195: hmac(Type, Keys, Data, Expected), 196: hmac(Type, lists:map(fun iolistify/1, Keys), lists:map(fun iolistify/1, Data), Expected), 197: hmac_increment(Type). 198: %%-------------------------------------------------------------------- 199: block() -> 200: [{doc, "Test block ciphers"}]. 201: block(Config) when is_list(Config) -> 202: Blocks = proplists:get_value(block, Config), 203: lists:foreach(fun block_cipher/1, Blocks), 204: lists:foreach(fun block_cipher/1, block_iolistify(Blocks)), 205: lists:foreach(fun block_cipher_increment/1, block_iolistify(Blocks)). 206: 207: %%-------------------------------------------------------------------- 208: stream() -> 209: [{doc, "Test stream ciphers"}]. 210: stream(Config) when is_list(Config) -> 211: Streams = lazy_eval(proplists:get_value(stream, Config)), 212: 213: lists:foreach(fun stream_cipher/1, Streams), 214: lists:foreach(fun stream_cipher/1, stream_iolistify(Streams)), 215: lists:foreach(fun stream_cipher_incment/1, stream_iolistify(Streams)). 216: 217: %%-------------------------------------------------------------------- 218: aead() -> 219: [{doc, "Test AEAD ciphers"}]. 220: aead(Config) when is_list(Config) -> 221: AEADs = lazy_eval(proplists:get_value(aead, Config)), 222: 223: lists:foreach(fun aead_cipher/1, AEADs). 224: 225: %%-------------------------------------------------------------------- 226: sign_verify() -> 227: [{doc, "Sign/verify digital signatures"}]. 228: sign_verify(Config) when is_list(Config) -> 229: SignVerify = proplists:get_value(sign_verify, Config), 230: lists:foreach(fun do_sign_verify/1, SignVerify). 231: 232: %%-------------------------------------------------------------------- 233: public_encrypt() -> 234: [{doc, "Test public_encrypt/decrypt and private_encrypt/decrypt functions. "}]. 235: public_encrypt(Config) when is_list(Config) -> 236: Params = proplists:get_value(pub_priv_encrypt, Config), 237: lists:foreach(fun do_public_encrypt/1, Params), 238: lists:foreach(fun do_private_encrypt/1, Params). 239: 240: %%-------------------------------------------------------------------- 241: generate_compute() -> 242: [{doc, " Test crypto:genarate_key and crypto:compute_key"}]. 243: generate_compute(Config) when is_list(Config) -> 244: GenCom = proplists:get_value(generate_compute, Config), 245: lists:foreach(fun do_generate_compute/1, GenCom). 246: %%-------------------------------------------------------------------- 247: compute() -> 248: [{doc, " Test crypto:compute_key"}]. 249: compute(Config) when is_list(Config) -> 250: Gen = proplists:get_value(compute, Config), 251: lists:foreach(fun do_compute/1, Gen). 252: %%-------------------------------------------------------------------- 253: generate() -> 254: [{doc, " Test crypto:generate_key"}]. 255: generate(Config) when is_list(Config) -> 256: Gen = proplists:get_value(generate, Config), 257: lists:foreach(fun do_generate/1, Gen). 258: %%-------------------------------------------------------------------- 259: mod_pow() -> 260: [{doc, "mod_pow testing (A ^ M % P with bignums)"}]. 261: mod_pow(Config) when is_list(Config) -> 262: mod_pow_aux_test(2, 5, 10, 8). 263: %%-------------------------------------------------------------------- 264: exor() -> 265: [{doc, "Test the exor function"}]. 266: exor(Config) when is_list(Config) -> 267: do_exor(<<1, 2, 3, 4, 5, 6, 7, 8, 9, 10>>), 268: do_exor(term_to_binary(lists:seq(1, 1000000))). 269: %%-------------------------------------------------------------------- 270: rand_uniform() -> 271: [{doc, "rand_uniform and random_bytes testing"}]. 272: rand_uniform(Config) when is_list(Config) -> 273: rand_uniform_aux_test(10), 274: 10 = byte_size(crypto:strong_rand_bytes(10)). 275: 276: %%-------------------------------------------------------------------- 277: %% Internal functions ------------------------------------------------ 278: %%-------------------------------------------------------------------- 279: hash(_, [], []) -> 280: ok; 281: hash(Type, [Msg | RestMsg], [Digest| RestDigest]) -> 282: case crypto:hash(Type, Msg) of 283: Digest -> 284: hash(Type, RestMsg, RestDigest); 285: Other -> 286: ct:fail({{crypto, hash, [Type, Msg]}, {expected, Digest}, {got, Other}}) 287: end. 288: 289: hash_increment(Type, Increments, Digest) -> 290: State = crypto:hash_init(Type), 291: case hash_increment(State, Increments) of 292: Digest -> 293: ok; 294: Other -> 295: ct:fail({{crypto, "hash_init/update/final", [Type, Increments]}, {expected, Digest}, {got, Other}}) 296: end. 297: 298: hash_increment(State, []) -> 299: crypto:hash_final(State); 300: hash_increment(State0, [Increment | Rest]) -> 301: State = crypto:hash_update(State0, Increment), 302: hash_increment(State, Rest). 303: 304: hmac(_, [],[],[]) -> 305: ok; 306: hmac(sha = Type, [Key | Keys], [ <<"Test With Truncation">> = Data| Rest], [Expected | Expects]) -> 307: case crypto:hmac(Type, Key, Data, 20) of 308: Expected -> 309: ok; 310: Other -> 311: ct:fail({{crypto, hmac, [Type, Key, Data]}, {expected, Expected}, {got, Other}}) 312: end, 313: hmac(Type, Keys, Rest, Expects); 314: 315: hmac(Type, [Key | Keys], [ <<"Test With Truncation">> = Data| Rest], [Expected | Expects]) -> 316: case crypto:hmac(Type, Key, Data, 16) of 317: Expected -> 318: ok; 319: Other -> 320: ct:fail({{crypto, hmac, [Type, Key, Data]}, {expected, Expected}, {got, Other}}) 321: end, 322: hmac(Type, Keys, Rest, Expects); 323: 324: hmac(Type, [Key | Keys], [Data| Rest], [Expected | Expects]) -> 325: case crypto:hmac(Type, Key, Data) of 326: Expected -> 327: ok; 328: Other -> 329: ct:fail({{crypto, hmac, [Type, Key, Data]}, {expected, Expected}, {got, Other}}) 330: end, 331: hmac(Type, Keys, Rest, Expects). 332: 333: hmac_increment(Type) -> 334: Key = hmac_key(Type), 335: Increments = hmac_inc(Type), 336: Expected = crypto:hmac(Type, Key, lists:flatten(Increments)), 337: State = crypto:hmac_init(Type, Key), 338: case hmac_increment(State, Increments) of 339: Expected -> 340: ok; 341: Other -> 342: ct:fail({{crypto, "hmac_init/update/final", [Type, Increments]}, {expected, Expected}, {got, Other}}) 343: end. 344: 345: hmac_increment(State, []) -> 346: crypto:hmac_final(State); 347: hmac_increment(State0, [Increment | Rest]) -> 348: State = crypto:hmac_update(State0, Increment), 349: hmac_increment(State, Rest). 350: 351: block_cipher({Type, Key, PlainText}) -> 352: Plain = iolist_to_binary(PlainText), 353: CipherText = crypto:block_encrypt(Type, Key, PlainText), 354: case crypto:block_decrypt(Type, Key, CipherText) of 355: Plain -> 356: ok; 357: Other -> 358: ct:fail({{crypto, block_decrypt, [Type, Key, CipherText]}, {expected, Plain}, {got, Other}}) 359: end; 360: 361: block_cipher({Type, Key, IV, PlainText}) -> 362: Plain = iolist_to_binary(PlainText), 363: CipherText = crypto:block_encrypt(Type, Key, IV, PlainText), 364: case crypto:block_decrypt(Type, Key, IV, CipherText) of 365: Plain -> 366: ok; 367: Other -> 368: ct:fail({{crypto, block_decrypt, [Type, Key, IV, CipherText]}, {expected, Plain}, {got, Other}}) 369: end; 370: 371: block_cipher({Type, Key, IV, PlainText, CipherText}) -> 372: Plain = iolist_to_binary(PlainText), 373: case crypto:block_encrypt(Type, Key, IV, Plain) of 374: CipherText -> 375: ok; 376: Other0 -> 377: ct:fail({{crypto, block_encrypt, [Type, Key, IV, Plain]}, {expected, CipherText}, {got, Other0}}) 378: end, 379: case crypto:block_decrypt(Type, Key, IV, CipherText) of 380: Plain -> 381: ok; 382: Other1 -> 383: ct:fail({{crypto, block_decrypt, [Type, Key, IV, CipherText]}, {expected, Plain}, {got, Other1}}) 384: end. 385: 386: block_cipher_increment({Type, Key, IV, PlainTexts}) 387: when Type == des_cbc; Type == aes_cbc; Type == des3_cbc -> 388: block_cipher_increment(Type, Key, IV, IV, PlainTexts, iolist_to_binary(PlainTexts), []); 389: block_cipher_increment({Type, Key, IV, PlainTexts, _CipherText}) when Type == aes_cbc -> 390: Plain = iolist_to_binary(PlainTexts), 391: Blocks = [iolistify(Block) || << Block:128/bitstring >> <= Plain], 392: block_cipher_increment(Type, Key, IV, IV, Blocks, Plain, []); 393: block_cipher_increment({_Type, _, _, _}) -> 394: ok; 395: block_cipher_increment({_,_,_}) -> 396: ok. 397: block_cipher_increment(Type, Key, IV0, _IV, [], Plain, Acc) -> 398: CipherText = iolist_to_binary(lists:reverse(Acc)), 399: case crypto:block_decrypt(Type, Key, IV0, CipherText) of 400: Plain -> 401: ok; 402: Other -> 403: ct:fail({{crypto, block_decrypt, [Type, Key, IV0, CipherText]}, {expected, Plain}, {got, Other}}) 404: end; 405: block_cipher_increment(Type, Key, IV0, IV, [PlainText | PlainTexts], Plain, Acc) -> 406: CipherText = crypto:block_encrypt(Type, Key, IV, PlainText), 407: NextIV = crypto:next_iv(Type, CipherText), 408: block_cipher_increment(Type, Key, IV0, NextIV, PlainTexts, Plain, [CipherText | Acc]). 409: 410: stream_cipher({Type, Key, PlainText}) -> 411: Plain = iolist_to_binary(PlainText), 412: State = crypto:stream_init(Type, Key), 413: {_, CipherText} = crypto:stream_encrypt(State, PlainText), 414: case crypto:stream_decrypt(State, CipherText) of 415: {_, Plain} -> 416: ok; 417: Other -> 418: ct:fail({{crypto, stream_decrypt, [State, CipherText]}, {expected, PlainText}, {got, Other}}) 419: end; 420: stream_cipher({Type, Key, IV, PlainText}) -> 421: Plain = iolist_to_binary(PlainText), 422: State = crypto:stream_init(Type, Key, IV), 423: {_, CipherText} = crypto:stream_encrypt(State, PlainText), 424: case crypto:stream_decrypt(State, CipherText) of 425: {_, Plain} -> 426: ok; 427: Other -> 428: ct:fail({{crypto, stream_decrypt, [State, CipherText]}, {expected, PlainText}, {got, Other}}) 429: end. 430: 431: stream_cipher_incment({Type, Key, PlainTexts}) -> 432: State = crypto:stream_init(Type, Key), 433: stream_cipher_incment(State, State, PlainTexts, [], iolist_to_binary(PlainTexts)); 434: stream_cipher_incment({Type, Key, IV, PlainTexts}) -> 435: State = crypto:stream_init(Type, Key, IV), 436: stream_cipher_incment(State, State, PlainTexts, [], iolist_to_binary(PlainTexts)). 437: 438: stream_cipher_incment(_State, OrigState, [], Acc, Plain) -> 439: CipherText = iolist_to_binary(lists:reverse(Acc)), 440: case crypto:stream_decrypt(OrigState, CipherText) of 441: {_, Plain} -> 442: ok; 443: Other -> 444: ct:fail({{crypto, stream_decrypt, [OrigState, CipherText]}, {expected, Plain}, {got, Other}}) 445: end; 446: stream_cipher_incment(State0, OrigState, [PlainText | PlainTexts], Acc, Plain) -> 447: {State, CipherText} = crypto:stream_encrypt(State0, PlainText), 448: stream_cipher_incment(State, OrigState, PlainTexts, [CipherText | Acc], Plain). 449: 450: aead_cipher({Type, Key, PlainText, IV, AAD, CipherText, CipherTag}) -> 451: Plain = iolist_to_binary(PlainText), 452: case crypto:block_encrypt(Type, Key, IV, {AAD, Plain}) of 453: {CipherText, CipherTag} -> 454: ok; 455: Other0 -> 456: ct:fail({{crypto, block_encrypt, [Plain, PlainText]}, {expected, {CipherText, CipherTag}}, {got, Other0}}) 457: end, 458: case crypto:block_decrypt(Type, Key, IV, {AAD, CipherText, CipherTag}) of 459: Plain -> 460: ok; 461: Other1 -> 462: ct:fail({{crypto, block_decrypt, [CipherText]}, {expected, Plain}, {got, Other1}}) 463: end; 464: aead_cipher({Type, Key, PlainText, IV, AAD, CipherText, CipherTag, TagLen}) -> 465: <<TruncatedCipherTag:TagLen/binary, _/binary>> = CipherTag, 466: Plain = iolist_to_binary(PlainText), 467: case crypto:block_encrypt(Type, Key, IV, {AAD, Plain, TagLen}) of 468: {CipherText, TruncatedCipherTag} -> 469: ok; 470: Other0 -> 471: ct:fail({{crypto, block_encrypt, [Plain, PlainText]}, {expected, {CipherText, TruncatedCipherTag}}, {got, Other0}}) 472: end, 473: case crypto:block_decrypt(Type, Key, IV, {AAD, CipherText, TruncatedCipherTag}) of 474: Plain -> 475: ok; 476: Other1 -> 477: ct:fail({{crypto, block_decrypt, [CipherText]}, {expected, Plain}, {got, Other1}}) 478: end. 479: 480: do_sign_verify({Type, Hash, Public, Private, Msg}) -> 481: Signature = crypto:sign(Type, Hash, Msg, Private), 482: case crypto:verify(Type, Hash, Msg, Signature, Public) of 483: true -> 484: negative_verify(Type, Hash, Msg, <<10,20>>, Public); 485: false -> 486: ct:fail({{crypto, verify, [Type, Hash, Msg, Signature, Public]}}) 487: end. 488: 489: negative_verify(Type, Hash, Msg, Signature, Public) -> 490: case crypto:verify(Type, Hash, Msg, Signature, Public) of 491: true -> 492: ct:fail({{crypto, verify, [Type, Hash, Msg, Signature, Public]}, should_fail}); 493: false -> 494: ok 495: end. 496: 497: do_public_encrypt({Type, Public, Private, Msg, Padding}) -> 498: PublicEcn = (catch crypto:public_encrypt(Type, Msg, Public, Padding)), 499: case crypto:private_decrypt(Type, PublicEcn, Private, Padding) of 500: Msg -> 501: ok; 502: Other -> 503: ct:fail({{crypto, private_decrypt, [Type, PublicEcn, Private, Padding]}, {expected, Msg}, {got, Other}}) 504: end. 505: 506: do_private_encrypt({_Type, _Public, _Private, _Msg, rsa_pkcs1_oaep_padding}) -> 507: ok; %% Not supported by openssl 508: do_private_encrypt({Type, Public, Private, Msg, Padding}) -> 509: PrivEcn = (catch crypto:private_encrypt(Type, Msg, Private, Padding)), 510: case crypto:public_decrypt(rsa, PrivEcn, Public, Padding) of 511: Msg -> 512: ok; 513: Other -> 514: ct:fail({{crypto, public_decrypt, [Type, PrivEcn, Public, Padding]}, {expected, Msg}, {got, Other}}) 515: end. 516: 517: do_generate_compute({srp = Type, UserPrivate, UserGenParams, UserComParams, 518: HostPublic, HostPrivate, HostGenParams, HostComParam, SessionKey}) -> 519: {UserPublic, UserPrivate} = crypto:generate_key(Type, UserGenParams, UserPrivate), 520: {HostPublic, HostPrivate} = crypto:generate_key(Type, HostGenParams, HostPrivate), 521: SessionKey = crypto:compute_key(Type, HostPublic, {UserPublic, UserPrivate}, 522: UserComParams), 523: SessionKey = crypto:compute_key(Type, UserPublic, {HostPublic, HostPrivate}, 524: HostComParam); 525: do_generate_compute({dh, P, G}) -> 526: {UserPub, UserPriv} = crypto:generate_key(dh, [P, G]), 527: {HostPub, HostPriv} = crypto:generate_key(dh, [P, G]), 528: SharedSecret = crypto:compute_key(dh, HostPub, UserPriv, [P, G]), 529: SharedSecret = crypto:compute_key(dh, UserPub, HostPriv, [P, G]). 530: 531: do_compute({ecdh = Type, Pub, Priv, Curve, SharedSecret}) -> 532: Secret = crypto:compute_key(Type, Pub, Priv, Curve), 533: case Secret of 534: SharedSecret -> 535: ok; 536: Other -> 537: ct:fail({{crypto, compute_key, [Type, Pub, Priv, Curve]}, {expected, SharedSecret}, {got, Other}}) 538: end. 539: 540: do_generate({ecdh = Type, Curve, Priv, Pub}) -> 541: case crypto:generate_key(Type, Curve, Priv) of 542: {Pub, _} -> 543: ok; 544: {Other, _} -> 545: ct:fail({{crypto, generate_key, [Type, Priv, Curve]}, {expected, Pub}, {got, Other}}) 546: end. 547: 548: hexstr2point(X, Y) -> 549: <<4:8, (hexstr2bin(X))/binary, (hexstr2bin(Y))/binary>>. 550: 551: hexstr2bin(S) -> 552: list_to_binary(hexstr2list(S)). 553: 554: hexstr2list([X,Y|T]) -> 555: [mkint(X)*16 + mkint(Y) | hexstr2list(T)]; 556: hexstr2list([]) -> 557: []. 558: mkint(C) when $0 =< C, C =< $9 -> 559: C - $0; 560: mkint(C) when $A =< C, C =< $F -> 561: C - $A + 10; 562: mkint(C) when $a =< C, C =< $f -> 563: C - $a + 10. 564: 565: is_supported(Group) -> 566: lists:member(Group, lists:append([Algo || {_, Algo} <- crypto:supports()])). 567: 568: block_iolistify(Blocks) -> 569: lists:map(fun do_block_iolistify/1, Blocks). 570: stream_iolistify(Streams) -> 571: lists:map(fun do_stream_iolistify/1, Streams). 572: 573: do_stream_iolistify({Type, Key, PlainText}) -> 574: {Type, iolistify(Key), iolistify(PlainText)}; 575: do_stream_iolistify({Type, Key, IV, PlainText}) -> 576: {Type, iolistify(Key), IV, iolistify(PlainText)}. 577: 578: do_block_iolistify({des_cbc = Type, Key, IV, PlainText}) -> 579: {Type, Key, IV, des_iolistify(PlainText)}; 580: do_block_iolistify({des3_cbc = Type, Key, IV, PlainText}) -> 581: {Type, Key, IV, des_iolistify(PlainText)}; 582: do_block_iolistify({des3_cbf = Type, Key, IV, PlainText}) -> 583: {Type, Key, IV, des_iolistify(PlainText)}; 584: do_block_iolistify({des3_cfb = Type, Key, IV, PlainText}) -> 585: {Type, Key, IV, des_iolistify(PlainText)}; 586: do_block_iolistify({des_ede3 = Type, Key, IV, PlainText}) -> 587: {Type, Key, IV, des_iolistify(PlainText)}; 588: do_block_iolistify({Type, Key, PlainText}) -> 589: {Type, iolistify(Key), iolistify(PlainText)}; 590: do_block_iolistify({Type, Key, IV, PlainText}) -> 591: {Type, iolistify(Key), IV, iolistify(PlainText)}; 592: do_block_iolistify({Type, Key, IV, PlainText, CipherText}) -> 593: {Type, iolistify(Key), IV, iolistify(PlainText), CipherText}. 594: 595: iolistify(<<"Test With Truncation">>)-> 596: %% Do not iolistify as it spoils this special case 597: <<"Test With Truncation">>; 598: iolistify(Msg) when is_binary(Msg) -> 599: Length = erlang:byte_size(Msg), 600: Split = Length div 2, 601: List0 = binary_to_list(Msg), 602: case lists:split(Split, List0) of 603: {[Element | List1], List2} -> 604: [[Element], List1, List2]; 605: {List1, List2}-> 606: [List1, List2] 607: end; 608: iolistify(Msg) -> 609: iolistify(list_to_binary(Msg)). 610: 611: des_iolistify(Msg) -> 612: des_iolist(erlang:byte_size(Msg) div 8, Msg, []). 613: 614: des_iolist(1, Msg, Acc) -> 615: lists:reverse([Msg | Acc]); 616: des_iolist(Split, Msg, Acc) -> 617: <<Part:8/binary, Rest/binary>> = Msg, 618: des_iolist(Split-1, Rest, [Part | Acc]). 619: 620: %%-------------------------------------------------------------------- 621: mod_pow_aux_test(_, _, _, 0) -> 622: ok; 623: mod_pow_aux_test(B, E, M, N) -> 624: Result = crypto:bytes_to_integer(crypto:mod_pow(B, E, M)), 625: Result = ipow(B, E, M), 626: mod_pow_aux_test(B, E*E+1, M*M+1, N-1). 627: 628: %% mod_exp in erlang (copied from jungerl's ssh_math.erl) 629: ipow(A, B, M) when M > 0, B >= 0 -> 630: if A == 1 -> 631: 1; 632: true -> 633: ipow(A, B, M, 1) 634: end. 635: 636: ipow(A, 1, M, Prod) -> 637: (A*Prod) rem M; 638: ipow(_A, 0, _M, Prod) -> 639: Prod; 640: ipow(A, B, M, Prod) -> 641: B1 = B bsr 1, 642: A1 = (A*A) rem M, 643: if B - B1 == B1 -> 644: ipow(A1, B1, M, Prod); 645: true -> 646: ipow(A1, B1, M, (A*Prod) rem M) 647: end. 648: 649: do_exor(B) -> 650: Z1 = zero_bin(B), 651: Z1 = crypto:exor(B, B), 652: B1 = crypto:strong_rand_bytes(100), 653: B2 = crypto:strong_rand_bytes(100), 654: Z2 = zero_bin(B1), 655: Z2 = crypto:exor(B1, B1), 656: Z2 = crypto:exor(B2, B2), 657: R = xor_bytes(B1, B2), 658: R = crypto:exor(B1, B2). 659: 660: zero_bin(N) when is_integer(N) -> 661: N8 = N * 8, 662: <<0:N8/integer>>; 663: zero_bin(B) when is_binary(B) -> 664: zero_bin(size(B)). 665: xor_bytes(Bin1, Bin2) when is_binary(Bin1), is_binary(Bin2) -> 666: L1 = binary_to_list(Bin1), 667: L2 = binary_to_list(Bin2), 668: list_to_binary(xor_bytes(L1, L2)); 669: xor_bytes(L1, L2) -> 670: xor_bytes(L1, L2, []). 671: 672: xor_bytes([], [], Acc) -> 673: lists:reverse(Acc); 674: xor_bytes([N1 | Tl1], [N2 | Tl2], Acc) -> 675: xor_bytes(Tl1, Tl2, [N1 bxor N2 | Acc]). 676: rand_uniform_aux_test(0) -> 677: ok; 678: rand_uniform_aux_test(N) -> 679: L = N*1000, 680: H = N*100000+1, 681: crypto_rand_uniform(L, H), 682: crypto_rand_uniform(-L, L), 683: crypto_rand_uniform(-H, -L), 684: crypto_rand_uniform(-H, L), 685: rand_uniform_aux_test(N-1). 686: 687: crypto_rand_uniform(L,H) -> 688: R1 = crypto:rand_uniform(L, H), 689: case (R1 >= L) and (R1 < H) of 690: true -> 691: ok; 692: false -> 693: ct:fail({"Not in interval", R1, L, H}) 694: end. 695: 696: %%-------------------------------------------------------------------- 697: %% Test data ------------------------------------------------ 698: %%-------------------------------------------------------------------- 699: group_config(md4 = Type, Config) -> 700: Msgs = rfc_1321_msgs(), 701: Digests = rfc_1321_md4_digests(), 702: [{hash, {Type, Msgs, Digests}} | Config]; 703: group_config(md5 = Type, Config) -> 704: Msgs = rfc_1321_msgs(), 705: Digests = rfc_1321_md5_digests(), 706: Keys = rfc_2202_md5_keys() ++ [long_hmac_key(md5)], 707: Data = rfc_2202_msgs() ++ [long_msg()], 708: Hmac = rfc_2202_hmac_md5() ++ [long_hmac(md5)], 709: [{hash, {Type, Msgs, Digests}}, {hmac, {Type, Keys, Data, Hmac}} | Config]; 710: group_config(ripemd160 = Type, Config) -> 711: Msgs = ripemd160_msgs(), 712: Digests = ripemd160_digests(), 713: [{hash, {Type, Msgs, Digests}} | Config]; 714: group_config(sha = Type, Config) -> 715: Msgs = [rfc_4634_test1(), rfc_4634_test2_1(),long_msg()], 716: Digests = rfc_4634_sha_digests() ++ [long_sha_digest()], 717: Keys = rfc_2202_sha_keys() ++ [long_hmac_key(sha)], 718: Data = rfc_2202_msgs() ++ [long_msg()], 719: Hmac = rfc_2202_hmac_sha() ++ [long_hmac(sha)], 720: [{hash, {Type, Msgs, Digests}}, {hmac, {Type, Keys, Data, Hmac}} | Config]; 721: group_config(sha224 = Type, Config) -> 722: Msgs = [rfc_4634_test1(), rfc_4634_test2_1()], 723: Digests = rfc_4634_sha224_digests(), 724: Keys = rfc_4231_keys(), 725: Data = rfc_4231_msgs(), 726: Hmac = rfc4231_hmac_sha224(), 727: [{hash, {Type, Msgs, Digests}}, {hmac, {Type, Keys, Data, Hmac}} | Config]; 728: group_config(sha256 = Type, Config) -> 729: Msgs = [rfc_4634_test1(), rfc_4634_test2_1(), long_msg()], 730: Digests = rfc_4634_sha256_digests() ++ [long_sha256_digest()], 731: Keys = rfc_4231_keys() ++ [long_hmac_key(sha256)], 732: Data = rfc_4231_msgs() ++ [long_msg()], 733: Hmac = rfc4231_hmac_sha256() ++ [long_hmac(sha256)], 734: [{hash, {Type, Msgs, Digests}}, {hmac, {Type, Keys, Data, Hmac}} | Config]; 735: group_config(sha384 = Type, Config) -> 736: Msgs = [rfc_4634_test1(), rfc_4634_test2(), long_msg()], 737: Digests = rfc_4634_sha384_digests() ++ [long_sha384_digest()], 738: Keys = rfc_4231_keys() ++ [long_hmac_key(sha384)], 739: Data = rfc_4231_msgs() ++ [long_msg()], 740: Hmac = rfc4231_hmac_sha384() ++ [long_hmac(sha384)], 741: [{hash, {Type, Msgs, Digests}}, {hmac, {Type, Keys, Data, Hmac}} | Config]; 742: group_config(sha512 = Type, Config) -> 743: Msgs = [rfc_4634_test1(), rfc_4634_test2(), long_msg()], 744: Digests = rfc_4634_sha512_digests() ++ [long_sha512_digest()], 745: Keys = rfc_4231_keys() ++ [long_hmac_key(sha512)], 746: Data = rfc_4231_msgs() ++ [long_msg()], 747: Hmac = rfc4231_hmac_sha512() ++ [long_hmac(sha512)], 748: [{hash, {Type, Msgs, Digests}}, {hmac, {Type, Keys, Data, Hmac}} | Config]; 749: group_config(rsa = Type, Config) -> 750: Msg = rsa_plain(), 751: Public = rsa_public(), 752: Private = rsa_private(), 753: PublicS = rsa_public_stronger(), 754: PrivateS = rsa_private_stronger(), 755: SignVerify = sign_verify_tests(Type, Msg, Public, Private, PublicS, PrivateS), 756: MsgPubEnc = <<"7896345786348 Asldi">>, 757: PubPrivEnc = [{rsa, Public, Private, MsgPubEnc, rsa_pkcs1_padding}, 758: rsa_oaep(), 759: no_padding() 760: ], 761: [{sign_verify, SignVerify}, {pub_priv_encrypt, PubPrivEnc} | Config]; 762: group_config(dss = Type, Config) -> 763: Msg = dss_plain(), 764: Public = dss_params() ++ [dss_public()], 765: Private = dss_params() ++ [dss_private()], 766: SignVerify = [{Type, sha, Public, Private, Msg}], 767: [{sign_verify, SignVerify} | Config]; 768: 769: group_config(ecdsa = Type, Config) -> 770: {Private, Public} = ec_key_named(), 771: Msg = ec_msg(), 772: SignVerify = [{Type, sha, Public, Private, Msg}], 773: [{sign_verify, SignVerify} | Config]; 774: group_config(srp, Config) -> 775: GenerateCompute = [srp3(), srp6(), srp6a(), srp6a_smaller_prime()], 776: [{generate_compute, GenerateCompute} | Config]; 777: group_config(ecdh, Config) -> 778: Compute = ecdh(), 779: Generate = ecc(), 780: [{compute, Compute}, {generate, Generate} | Config]; 781: group_config(dh, Config) -> 782: GenerateCompute = [dh()], 783: [{generate_compute, GenerateCompute} | Config]; 784: group_config(des_cbc, Config) -> 785: Block = des_cbc(), 786: [{block, Block} | Config]; 787: group_config(des_cfb, Config) -> 788: Block = des_cfb(), 789: [{block, Block} | Config]; 790: group_config(des3_cbc, Config) -> 791: Block = des3_cbc(), 792: [{block, Block} | Config]; 793: group_config(des3_cbf, Config) -> 794: Block = des3_cbf(), 795: [{block, Block} | Config]; 796: group_config(des3_cfb, Config) -> 797: Block = des3_cfb(), 798: [{block, Block} | Config]; 799: group_config(des_ede3, Config) -> 800: Block = des_ede3(), 801: [{block, Block} | Config]; 802: group_config(rc2_cbc, Config) -> 803: Block = rc2_cbc(), 804: [{block, Block} | Config]; 805: group_config(aes_cbc128, Config) -> 806: Block = aes_cbc128(), 807: [{block, Block} | Config]; 808: group_config(aes_cbc256, Config) -> 809: Block = aes_cbc256(), 810: [{block, Block} | Config]; 811: group_config(aes_ecb, Config) -> 812: Block = aes_ecb(), 813: [{block, Block} | Config]; 814: group_config(aes_ige256, Config) -> 815: Block = aes_ige256(), 816: [{block, Block} | Config]; 817: group_config(aes_cfb8, Config) -> 818: Block = aes_cfb8(), 819: [{block, Block} | Config]; 820: group_config(aes_cfb128, Config) -> 821: Block = aes_cfb128(), 822: [{block, Block} | Config]; 823: group_config(blowfish_cbc, Config) -> 824: Block = blowfish_cbc(), 825: [{block, Block} | Config]; 826: group_config(blowfish_ecb, Config) -> 827: Block = blowfish_ecb(), 828: [{block, Block} | Config]; 829: group_config(blowfish_cfb64, Config) -> 830: Block = blowfish_cfb64(), 831: [{block, Block} | Config]; 832: group_config(blowfish_ofb64, Config) -> 833: Block = blowfish_ofb64(), 834: [{block, Block} | Config]; 835: group_config(rc4, Config) -> 836: Stream = rc4(), 837: [{stream, Stream} | Config]; 838: group_config(aes_ctr, Config) -> 839: Stream = aes_ctr(), 840: [{stream, Stream} | Config]; 841: group_config(aes_gcm, Config) -> 842: AEAD = aes_gcm(), 843: [{aead, AEAD} | Config]; 844: group_config(chacha20_poly1305, Config) -> 845: AEAD = chacha20_poly1305(), 846: [{aead, AEAD} | Config]; 847: group_config(aes_cbc, Config) -> 848: Block = aes_cbc(), 849: [{block, Block} | Config]; 850: group_config(_, Config) -> 851: Config. 852: 853: sign_verify_tests(Type, Msg, Public, Private, PublicS, PrivateS) -> 854: sign_verify_tests(Type, [md5, sha, sha224, sha256], Msg, Public, Private) ++ 855: sign_verify_tests(Type, [sha384, sha512], Msg, PublicS, PrivateS). 856: 857: sign_verify_tests(Type, Hashs, Msg, Public, Private) -> 858: lists:foldl(fun(Hash, Acc) -> 859: case is_supported(Hash) of 860: true -> 861: [{Type, Hash, Public, Private, Msg}|Acc]; 862: false -> 863: Acc 864: end 865: end, [], Hashs). 866: 867: rfc_1321_msgs() -> 868: [<<"">>, 869: <<"a">>, 870: <<"abc">>, 871: <<"message digest">>, 872: <<"abcdefghijklmnopqrstuvwxyz">>, 873: <<"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789">>, 874: <<"12345678901234567890123456789012345678901234567890123456789012345678901234567890">> 875: ]. 876: 877: rfc_1321_md4_digests() -> 878: [hexstr2bin("31d6cfe0d16ae931b73c59d7e0c089c0"), 879: hexstr2bin("bde52cb31de33e46245e05fbdbd6fb24"), 880: hexstr2bin("a448017aaf21d8525fc10ae87aa6729d"), 881: hexstr2bin("d9130a8164549fe818874806e1c7014b"), 882: hexstr2bin("d79e1c308aa5bbcdeea8ed63df412da9"), 883: hexstr2bin("043f8582f241db351ce627e153e7f0e4"), 884: hexstr2bin("e33b4ddc9c38f2199c3e7b164fcc0536")]. 885: 886: rfc_1321_md5_digests() -> 887: [hexstr2bin("d41d8cd98f00b204e9800998ecf8427e"), 888: hexstr2bin("0cc175b9c0f1b6a831c399e269772661"), 889: hexstr2bin("900150983cd24fb0d6963f7d28e17f72"), 890: hexstr2bin("f96b697d7cb7938d525a2f31aaf161d0"), 891: hexstr2bin("c3fcd3d76192e4007dfb496cca67e13b"), 892: hexstr2bin("d174ab98d277d9f5a5611c2c9f419d9f"), 893: hexstr2bin("57edf4a22be3c955ac49da2e2107b67a")]. 894: 895: rfc_4634_test1() -> 896: <<"abc">>. 897: rfc_4634_test2_1() -> 898: <<"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq">>. 899: rfc_4634_test2_2a() -> 900: <<"abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn">>. 901: rfc_4634_test2_2b() -> 902: <<"hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu">>. 903: rfc_4634_test2() -> 904: A2 =rfc_4634_test2_2a(), 905: B2 = rfc_4634_test2_2b(), 906: <<A2/binary, B2/binary>>. 907: 908: rfc_4634_sha_digests()-> 909: [hexstr2bin("A9993E364706816ABA3E25717850C26C9CD0D89D"), 910: hexstr2bin("84983E441C3BD26EBAAE4AA1F95129E5E54670F1")]. 911: rfc_4634_sha224_digests() -> 912: [hexstr2bin("23097D223405D8228642A477BDA255B32AADBCE4BDA0B3F7E36C9DA7"), 913: hexstr2bin("75388B16512776CC5DBA5DA1FD890150B0C6455CB4F58B1952522525")]. 914: rfc_4634_sha256_digests() -> 915: [ 916: hexstr2bin("BA7816BF8F01CFEA4141" 917: "40DE5DAE2223B00361A396177A9CB410FF61F20015AD"), 918: hexstr2bin("248D6A61D20638B8" 919: "E5C026930C3E6039A33CE45964FF2167F6ECEDD419DB06C1") 920: ]. 921: rfc_4634_sha384_digests() -> 922: [hexstr2bin("CB00753F45A35E8BB5A03D699AC65007272C32AB0EDED1631A8B605A43FF5BED8086072BA1E7CC2358BAECA134C825A7"), 923: hexstr2bin("09330C33F71147E83D192FC782CD1B4753111B173B3B05D22FA08086E3B0F712FCC7C71A557E2DB966C3E9FA91746039") 924: ]. 925: rfc_4634_sha512_digests() -> 926: [hexstr2bin("DDAF35A193617ABACC417349AE20413112E6FA4E89A97EA2" 927: "0A9EEEE64B55D39A2192992A274FC1A836BA3C23A3FEEBBD" 928: "454D4423643CE80E2A9AC94FA54CA49F"), 929: hexstr2bin("8E959B75DAE313DA8CF4F72814FC143F8F7779C6EB9F7FA17299AEADB6889018501D289E4900F7E4331B99DEC4B5433AC7D329EEB6DD26545E96E55B874BE909")]. 930: 931: long_msg() -> 932: fun() -> lists:duplicate(1000000, $a) end. 933: 934: %% Building huge terms (like long_msg/0) in init_per_group seems to cause 935: %% test_server crash with 'no_answer_from_tc_supervisor' sometimes on some 936: %% machines. Therefore lazy evaluation when test case has started. 937: lazy_eval(F) when is_function(F) -> F(); 938: lazy_eval(Lst) when is_list(Lst) -> lists:map(fun lazy_eval/1, Lst); 939: lazy_eval(Tpl) when is_tuple(Tpl) -> list_to_tuple(lists:map(fun lazy_eval/1, tuple_to_list(Tpl))); 940: lazy_eval(Term) -> Term. 941: 942: long_sha_digest() -> 943: hexstr2bin("34aa973c" "d4c4daa4" "f61eeb2b" "dbad2731" "6534016f"). 944: 945: long_sha256_digest() -> 946: hexstr2bin("cdc76e5c" "9914fb92" "81a1c7e2" "84d73e67" "f1809a48" "a497200e" "046d39cc" "c7112cd0"). 947: 948: long_sha384_digest() -> 949: hexstr2bin("9d0e1809716474cb" "086e834e310a4a1c" "ed149e9c00f24852" "7972cec5704c2a5b" 950: "07b8b3dc38ecc4eb" "ae97ddd87f3d8985"). 951: 952: long_sha512_digest() -> 953: hexstr2bin("e718483d0ce76964" "4e2e42c7bc15b463" "8e1f98b13b204428" "5632a803afa973eb" 954: "de0ff244877ea60a" "4cb0432ce577c31b" "eb009c5c2c49aa2e" "4eadb217ad8cc09b"). 955: 956: ripemd160_msgs() -> 957: [<<"">>, 958: <<"a">>, 959: <<"abc">>, 960: <<"message digest">>, 961: <<"abcdefghijklmnopqrstuvwxyz">>, 962: <<"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq">>, 963: <<"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789">> 964: ]. 965: 966: ripemd160_digests() -> 967: [hexstr2bin("9c1185a5c5e9fc54612808977ee8f548b2258d31"), 968: hexstr2bin("0bdc9d2d256b3ee9daae347be6f4dc835a467ffe"), 969: hexstr2bin("8eb208f7e05d987a9b044a8e98c6b087f15a0bfc"), 970: hexstr2bin("5d0689ef49d2fae572b881b123a85ffa21595f36"), 971: hexstr2bin("f71c27109c692c1b56bbdceb5b9d2865b3708dbc"), 972: hexstr2bin("12a053384a9c0c88e405a06c27dcf49ada62eb2b"), 973: hexstr2bin("b0e20b6e3116640286ed3a87a5713079b21f5189") 974: ]. 975: 976: ripemd160_incr_msgs() -> 977: [<<"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefg">>,<<"hijklmnopqrstuvwxyz0123456789">>]. 978: ripemd160_incr_digest() -> 979: hexstr2bin("b0e20b6e3116640286ed3a87a5713079b21f5189"). 980: 981: rfc_2202_md5_keys() -> 982: [binary:copy(<<16#0b>>, 16), 983: <<"Jefe">>, 984: binary:copy(<<16#aa>>, 16), 985: list_to_binary(lists:seq(1, 16#19)), 986: binary:copy(<<16#0c>>, 16), 987: binary:copy(<<16#aa>>, 80), 988: binary:copy(<<16#aa>>, 80)]. 989: 990: rfc_2202_sha_keys() -> 991: [binary:copy(<<16#0b>>, 20), 992: <<"Jefe">>, 993: binary:copy(<<16#aa>>, 20), 994: list_to_binary(lists:seq(1, 16#19)), 995: binary:copy(<<16#0c>>, 20), 996: binary:copy(<<16#aa>>, 80), 997: binary:copy(<<16#aa>>, 80)]. 998: 999: rfc_2202_msgs()-> 1000: [<<"Hi There">>, 1001: <<"what do ya want for nothing?">>, 1002: binary:copy(<<16#dd>>, 50), 1003: binary:copy(<<16#cd>>, 50), 1004: <<"Test With Truncation">>, 1005: <<"Test Using Larger Than Block-Size Key - Hash Key First">>, 1006: <<"Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data">> 1007: ]. 1008: 1009: hmac_key(md5) -> 1010: [<<"A fine speach">>, <<"by a fine man!">>]; 1011: hmac_key(_) -> 1012: hexstr2bin("00010203101112132021222330313233" 1013: "04050607141516172425262734353637" 1014: "08090a0b18191a1b28292a2b38393a3b" 1015: "0c0d0e0f1c1d1e1f2c2d2e2f3c3d3e3f"). 1016: hmac_inc(_) -> 1017: [<<"Sampl">>, <<"e #1">>]. 1018: 1019: %% https://www.cosic.esat.kuleuven.be/nessie/testvectors/ 1020: long_hmac_key(Type) when Type == sha384; 1021: Type == sha512 -> 1022: hexstr2bin("00112233445566778899AABBCCDDEEFF" 1023: "0123456789ABCDEF0011223344556677" 1024: "8899AABBCCDDEEFF0123456789ABCDEF" 1025: "00112233445566778899AABBCCDDEEFF"); 1026: long_hmac_key(_) -> 1027: hexstr2bin("0123456789ABCDEF0123456789ABCDEF" 1028: "0123456789ABCDEF0123456789ABCDEF" 1029: "0123456789ABCDEF0123456789ABCDEF" 1030: "0123456789ABCDEF0123456789ABCDEF"). 1031: long_hmac(md5) -> 1032: hexstr2bin("82FDDA30202CB6ACC6F24D4F8A50EB7A"); 1033: long_hmac(sha) -> 1034: hexstr2bin("61D1D0B6459860755FDA892938C23DD401E54A7E"); 1035: long_hmac(sha256) -> 1036: hexstr2bin("50008B8DC7ED3926936347FDC1A01E9D" 1037: "5220C6CC4B038B482C0F28A4CD88CA37"); 1038: long_hmac(sha384) -> 1039: hexstr2bin("C1EB08DAFA015833D3FC6B29A387558B" 1040: "3F6FA1524AA1A8EB64798D5A76A39D6E" 1041: "A1465525342E060EE996277B4FFCDDC9"); 1042: long_hmac(sha512) -> 1043: hexstr2bin("D116BF471AAE1264854F1906025E846A" 1044: "61618A965FCA30B695220EA2D6E547E3" 1045: "F3B5A4B54E6778928C26D5D3D810498E" 1046: "8DF86CB3CC1E9F66A00419B13B6B0C9A"). 1047: 1048: rfc_2202_hmac_md5() -> 1049: [ 1050: hexstr2bin("9294727a3638bb1c13f48ef8158bfc9d"), 1051: hexstr2bin("750c783e6ab0b503eaa86e310a5db738"), 1052: hexstr2bin("56be34521d144c88dbb8c733f0e8b3f6"), 1053: hexstr2bin("697eaf0aca3a3aea3a75164746ffaa79"), 1054: hexstr2bin("56461ef2342edc00f9bab995690efd4c"), 1055: hexstr2bin("6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd"), 1056: hexstr2bin("6f630fad67cda0ee1fb1f562db3aa53e") 1057: ]. 1058: 1059: rfc_2202_hmac_sha() -> 1060: [ 1061: hexstr2bin("b617318655057264e28bc0b6fb378c8ef146be00"), 1062: hexstr2bin("effcdf6ae5eb2fa2d27416d5f184df9c259a7c79"), 1063: hexstr2bin("125d7342b9ac11cd91a39af48aa17b4f63f175d3"), 1064: hexstr2bin("4c9007f4026250c6bc8414f9bf50c86c2d7235da"), 1065: hexstr2bin("4c1a03424b55e07fe7f27be1d58bb9324a9a5a04"), 1066: hexstr2bin("aa4ae5e15272d00e95705637ce8a3b55ed402112"), 1067: hexstr2bin("e8e99d0f45237d786d6bbaa7965c7808bbff1a91") 1068: ]. 1069: 1070: 1071: rfc_4231_keys() -> 1072: [binary:copy(<<16#0b>>, 20), 1073: <<"Jefe">>, 1074: binary:copy(<<16#aa>>, 20), 1075: list_to_binary(lists:seq(1, 16#19)), 1076: binary:copy(<<16#0c>>, 20), 1077: binary:copy(<<16#aa>>, 131), 1078: binary:copy(<<16#aa>>, 131) 1079: ]. 1080: 1081: rfc_4231_msgs() -> 1082: [<<"Hi There">>, 1083: <<"what do ya want for nothing?">>, 1084: binary:copy(<<16#dd>>, 50), 1085: binary:copy(<<16#cd>>, 50), 1086: <<"Test With Truncation">>, 1087: <<"Test Using Larger Than Block-Size Key - Hash Key First">>, 1088: <<"This is a test using a larger than block-size key and a larger t", 1089: "han block-size data. The key needs to be hashed before being use", 1090: "d by the HMAC algorithm.">> 1091: ]. 1092: 1093: rfc4231_hmac_sha224() -> 1094: [hexstr2bin("896fb1128abbdf196832107cd49df33f" 1095: "47b4b1169912ba4f53684b22"), 1096: hexstr2bin("a30e01098bc6dbbf45690f3a7e9e6d0f" 1097: "8bbea2a39e6148008fd05e44"), 1098: hexstr2bin("7fb3cb3588c6c1f6ffa9694d7d6ad264" 1099: "9365b0c1f65d69d1ec8333ea"), 1100: hexstr2bin("6c11506874013cac6a2abc1bb382627c" 1101: "ec6a90d86efc012de7afec5a"), 1102: hexstr2bin("0e2aea68a90c8d37c988bcdb9fca6fa8"), 1103: hexstr2bin("95e9a0db962095adaebe9b2d6f0dbce2" 1104: "d499f112f2d2b7273fa6870e"), 1105: hexstr2bin("3a854166ac5d9f023f54d517d0b39dbd" 1106: "946770db9c2b95c9f6f565d1")]. 1107: rfc4231_hmac_sha256() -> 1108: [hexstr2bin("b0344c61d8db38535ca8afceaf0bf12b" 1109: "881dc200c9833da726e9376c2e32cff7"), 1110: hexstr2bin("5bdcc146bf60754e6a042426089575c7" 1111: "5a003f089d2739839dec58b964ec3843"), 1112: hexstr2bin("773ea91e36800e46854db8ebd09181a7" 1113: "2959098b3ef8c122d9635514ced565fe"), 1114: hexstr2bin("82558a389a443c0ea4cc819899f2083a" 1115: "85f0faa3e578f8077a2e3ff46729665b"), 1116: hexstr2bin("a3b6167473100ee06e0c796c2955552b"), 1117: hexstr2bin("60e431591ee0b67f0d8a26aacbf5b77f" 1118: "8e0bc6213728c5140546040f0ee37f54"), 1119: hexstr2bin("9b09ffa71b942fcb27635fbcd5b0e944" 1120: "bfdc63644f0713938a7f51535c3a35e2")]. 1121: 1122: rfc4231_hmac_sha384() -> 1123: [hexstr2bin("afd03944d84895626b0825f4ab46907f" 1124: "15f9dadbe4101ec682aa034c7cebc59c" 1125: "faea9ea9076ede7f4af152e8b2fa9cb6"), 1126: hexstr2bin("af45d2e376484031617f78d2b58a6b1b" 1127: "9c7ef464f5a01b47e42ec3736322445e" 1128: "8e2240ca5e69e2c78b3239ecfab21649"), 1129: hexstr2bin("88062608d3e6ad8a0aa2ace014c8a86f" 1130: "0aa635d947ac9febe83ef4e55966144b" 1131: "2a5ab39dc13814b94e3ab6e101a34f27"), 1132: hexstr2bin("3e8a69b7783c25851933ab6290af6ca7" 1133: "7a9981480850009cc5577c6e1f573b4e" 1134: "6801dd23c4a7d679ccf8a386c674cffb"), 1135: hexstr2bin("3abf34c3503b2a23a46efc619baef897"), 1136: hexstr2bin("4ece084485813e9088d2c63a041bc5b4" 1137: "4f9ef1012a2b588f3cd11f05033ac4c6" 1138: "0c2ef6ab4030fe8296248df163f44952"), 1139: hexstr2bin("6617178e941f020d351e2f254e8fd32c" 1140: "602420feb0b8fb9adccebb82461e99c5" 1141: "a678cc31e799176d3860e6110c46523e")]. 1142: rfc4231_hmac_sha512() -> 1143: [hexstr2bin("87aa7cdea5ef619d4ff0b4241a1d6cb0" 1144: "2379f4e2ce4ec2787ad0b30545e17cde" 1145: "daa833b7d6b8a702038b274eaea3f4e4" 1146: "be9d914eeb61f1702e696c203a126854"), 1147: hexstr2bin("164b7a7bfcf819e2e395fbe73b56e0a3" 1148: "87bd64222e831fd610270cd7ea250554" 1149: "9758bf75c05a994a6d034f65f8f0e6fd" 1150: "caeab1a34d4a6b4b636e070a38bce737"), 1151: hexstr2bin("fa73b0089d56a284efb0f0756c890be9" 1152: "b1b5dbdd8ee81a3655f83e33b2279d39" 1153: "bf3e848279a722c806b485a47e67c807" 1154: "b946a337bee8942674278859e13292fb"), 1155: hexstr2bin("b0ba465637458c6990e5a8c5f61d4af7" 1156: "e576d97ff94b872de76f8050361ee3db" 1157: "a91ca5c11aa25eb4d679275cc5788063" 1158: "a5f19741120c4f2de2adebeb10a298dd"), 1159: hexstr2bin("415fad6271580a531d4179bc891d87a6"), 1160: hexstr2bin("80b24263c7c1a3ebb71493c1dd7be8b4" 1161: "9b46d1f41b4aeec1121b013783f8f352" 1162: "6b56d037e05f2598bd0fd2215d6a1e52" 1163: "95e64f73f63f0aec8b915a985d786598"), 1164: hexstr2bin("e37b6a775dc87dbaa4dfa9f96e5e3ffd" 1165: "debd71f8867289865df5a32d20cdc944" 1166: "b6022cac3c4982b10d5eeb55c3e4de15" 1167: "134676fb6de0446065c97440fa8c6a58")]. 1168: des_cbc() -> 1169: [{des_cbc, 1170: hexstr2bin("0123456789abcdef"), 1171: hexstr2bin("1234567890abcdef"), 1172: <<"Now is the time for all ">> }]. 1173: 1174: des_cfb() -> 1175: [{des_cfb, 1176: hexstr2bin("0123456789abcdef"), 1177: hexstr2bin("1234567890abcdef"), 1178: <<"Now is the">>}]. 1179: 1180: des3_cbc() -> 1181: [{des3_cbc, 1182: [hexstr2bin("0123456789abcdef"), 1183: hexstr2bin("fedcba9876543210"), 1184: hexstr2bin("0f2d4b6987a5c3e1")], 1185: hexstr2bin("1234567890abcdef"), 1186: <<"Now is the time for all ">> 1187: }]. 1188: 1189: des_ede3() -> 1190: [{des_ede3, 1191: [hexstr2bin("8000000000000000"), 1192: hexstr2bin("4000000000000000"), 1193: hexstr2bin("2000000000000000")], 1194: hexstr2bin("7AD16FFB79C45926"), 1195: hexstr2bin("0000000000000000") 1196: }]. 1197: 1198: des3_cbf() -> 1199: [{des3_cbf, 1200: [hexstr2bin("0123456789abcdef"), 1201: hexstr2bin("fedcba9876543210"), 1202: hexstr2bin("0f2d4b6987a5c3e1")], 1203: hexstr2bin("1234567890abcdef"), 1204: <<"Now is the time for all ">> 1205: }]. 1206: 1207: des3_cfb() -> 1208: [{des3_cfb, 1209: [hexstr2bin("0123456789abcdef"), 1210: hexstr2bin("fedcba9876543210"), 1211: hexstr2bin("0f2d4b6987a5c3e1")], 1212: hexstr2bin("1234567890abcdef"), 1213: <<"Now is the time for all ">> 1214: }]. 1215: 1216: rc2_cbc() -> 1217: [{rc2_cbc, 1218: <<146,210,160,124,215,227,153,239,227,17,222,140,3,93,27,191>>, 1219: <<72,91,135,182,25,42,35,210>>, 1220: <<36,245,206,158,168,230,58,69,148,137,32,192,250,41,237,181,181,251, 192,2,175,135,177,171,57,30,111,117,159,149,15,28,88,158,28,81,28,115, 85,219,241,82,117,222,91,85,73,117,164,25,182,52,191,64,123,57,26,19, 211,27,253,31,194,219,231,104,247,240,172,130,119,21,225,154,101,247, 32,216,42,216,133,169,78,22,97,27,227,26,196,224,172,168,17,9,148,55, 203,91,252,40,61,226,236,221,215,160,78,63,13,181,68,57,196,241,185, 207, 116,129,152,237,60,139,247,153,27,146,161,246,222,98,185,222,152, 187,135, 236,86,34,7,110,91,230,173,34,160,242,202,222,121,127,181,140, 101,203,195, 190,88,250,86,147,127,87,72,126,171,16,71,47,110,248,88, 14,29,143,161,152, 129,236,148,22,152,186,208,119,70,8,174,193,203,100, 193,203,200,117,102,242, 134,142,96,125,135,200,217,190,76,117,50,70, 209,186,101,241,200,91,40,193,54, 90,195,38,47,59,197,38,234,86,223,16, 51,253,204,129,20,171,66,21,241,26,135,216, 196,114,110,91,15,53,40, 164,201,136,113,95,247,51,181,208,241,68,168,98,151,36, 155,72,24,57, 42,191,14,125,204,10,167,214,233,138,115,125,234,121,134,227,26,247, 77,200,117,110,117,111,168,156,206,67,159,149,189,173,150,193,91,199, 216,153,22, 189,137,185,89,160,13,131,132,58,109,28,110,246,252,251,14, 232,91,38,52,29,101,188,69,123,50,0,130,178,93,73,239,118,7,77,35,59, 253,10,159,45,86,142,37,78,232,48>> 1221: }]. 1222: 1223: %% AES CBC test vectors from http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf 1224: aes_cbc() -> 1225: [ 1226: %% F.2.1 CBC-AES128.Encrypt, F.2.2 CBC-AES128.Decrypt 1227: {aes_cbc, 1228: hexstr2bin("2b7e151628aed2a6abf7158809cf4f3c"), %% Key 1229: hexstr2bin("000102030405060708090a0b0c0d0e0f"), %% IV 1230: hexstr2bin("6bc1bee22e409f96e93d7e117393172a" %% PlainText 1231: "ae2d8a571e03ac9c9eb76fac45af8e51" 1232: "30c81c46a35ce411e5fbc1191a0a52ef" 1233: "f69f2445df4f9b17ad2b417be66c3710"), 1234: hexstr2bin("7649abac8119b246cee98e9b12e9197d" %% CipherText 1235: "5086cb9b507219ee95db113a917678b2" 1236: "73bed6b8e3c1743b7116e69e22229516" 1237: "3ff1caa1681fac09120eca307586e1a7")}, 1238: %% F.2.3 CBC-AES192.Encrypt, F.2.4 CBC-AES192.Decrypt 1239: {aes_cbc, 1240: hexstr2bin("8e73b0f7da0e6452c810f32b809079e5" %% Key 1241: "62f8ead2522c6b7b"), 1242: hexstr2bin("000102030405060708090a0b0c0d0e0f"), %% IV 1243: hexstr2bin("6bc1bee22e409f96e93d7e117393172a" %% PlainText 1244: "ae2d8a571e03ac9c9eb76fac45af8e51" 1245: "30c81c46a35ce411e5fbc1191a0a52ef" 1246: "f69f2445df4f9b17ad2b417be66c3710"), 1247: hexstr2bin("4f021db243bc633d7178183a9fa071e8" %% CipherText 1248: "b4d9ada9ad7dedf4e5e738763f69145a" 1249: "571b242012fb7ae07fa9baac3df102e0" 1250: "08b0e27988598881d920a9e64f5615cd")}, 1251: %% F.2.5 CBC-AES256.Encrypt, F.2.6 CBC-AES256.Decrypt 1252: {aes_cbc, 1253: hexstr2bin("603deb1015ca71be2b73aef0857d7781" %% Key 1254: "1f352c073b6108d72d9810a30914dff4"), 1255: hexstr2bin("000102030405060708090a0b0c0d0e0f"), %% IV 1256: hexstr2bin("6bc1bee22e409f96e93d7e117393172a" %% PlainText 1257: "ae2d8a571e03ac9c9eb76fac45af8e51" 1258: "30c81c46a35ce411e5fbc1191a0a52ef" 1259: "f69f2445df4f9b17ad2b417be66c3710"), 1260: hexstr2bin("f58c4c04d6e5f1ba779eabfb5f7bfbd6" %% CipherText 1261: "9cfc4e967edb808d679f777bc6702c7d" 1262: "39f23369a9d9bacfa530e26304231461" 1263: "b2eb05e2c39be9fcda6c19078c6a9d1b")} 1264: ]. 1265: 1266: aes_cbc128() -> 1267: [{aes_cbc128, 1268: hexstr2bin("2b7e151628aed2a6abf7158809cf4f3c"), 1269: hexstr2bin("000102030405060708090a0b0c0d0e0f"), 1270: hexstr2bin("6bc1bee22e409f96e93d7e117393172a")}, 1271: {aes_cbc128, 1272: hexstr2bin("2b7e151628aed2a6abf7158809cf4f3c"), 1273: hexstr2bin("7649ABAC8119B246CEE98E9B12E9197D"), 1274: hexstr2bin("ae2d8a571e03ac9c9eb76fac45af8e51")}, 1275: {aes_cbc128, 1276: hexstr2bin("2b7e151628aed2a6abf7158809cf4f3c"), 1277: hexstr2bin("5086CB9B507219EE95DB113A917678B2"), 1278: hexstr2bin("30c81c46a35ce411e5fbc1191a0a52ef")}, 1279: {aes_cbc128, 1280: hexstr2bin("2b7e151628aed2a6abf7158809cf4f3c"), 1281: hexstr2bin("73BED6B8E3C1743B7116E69E22229516"), 1282: hexstr2bin("f69f2445df4f9b17ad2b417be66c3710")} 1283: ]. 1284: 1285: aes_cbc256() -> 1286: [{aes_cbc256, 1287: hexstr2bin("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"), 1288: hexstr2bin("000102030405060708090A0B0C0D0E0F"), 1289: hexstr2bin("6bc1bee22e409f96e93d7e117393172a")}, 1290: {aes_cbc256, 1291: hexstr2bin("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"), 1292: hexstr2bin("F58C4C04D6E5F1BA779EABFB5F7BFBD6"), 1293: hexstr2bin("ae2d8a571e03ac9c9eb76fac45af8e51")}, 1294: {aes_cbc256, 1295: hexstr2bin("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"), 1296: hexstr2bin("9CFC4E967EDB808D679F777BC6702C7D"), 1297: hexstr2bin("30c81c46a35ce411e5fbc1191a0a52ef")}, 1298: {aes_cbc256, 1299: hexstr2bin("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"), 1300: hexstr2bin("39F23369A9D9BACFA530E26304231461"), 1301: hexstr2bin("f69f2445df4f9b17ad2b417be66c3710")} 1302: ]. 1303: 1304: aes_ecb() -> 1305: [ 1306: {aes_ecb, 1307: <<"YELLOW SUBMARINE">>, 1308: <<"YELLOW SUBMARINE">>}, 1309: {aes_ecb, 1310: <<"0000000000000000">>, 1311: <<"0000000000000000">>}, 1312: {aes_ecb, 1313: <<"FFFFFFFFFFFFFFFF">>, 1314: <<"FFFFFFFFFFFFFFFF">>}, 1315: {aes_ecb, 1316: <<"3000000000000000">>, 1317: <<"1000000000000001">>}, 1318: {aes_ecb, 1319: <<"1111111111111111">>, 1320: <<"1111111111111111">>}, 1321: {aes_ecb, 1322: <<"0123456789ABCDEF">>, 1323: <<"1111111111111111">>}, 1324: {aes_ecb, 1325: <<"0000000000000000">>, 1326: <<"0000000000000000">>}, 1327: {aes_ecb, 1328: <<"FEDCBA9876543210">>, 1329: <<"0123456789ABCDEF">>}, 1330: {aes_ecb, 1331: <<"7CA110454A1A6E57">>, 1332: <<"01A1D6D039776742">>}, 1333: {aes_ecb, 1334: <<"0131D9619DC1376E">>, 1335: <<"5CD54CA83DEF57DA">>}, 1336: {aes_ecb, 1337: <<"07A1133E4A0B2686">>, 1338: <<"0248D43806F67172">>}, 1339: {aes_ecb, 1340: <<"3849674C2602319E">>, 1341: <<"51454B582DDF440A">>}, 1342: {aes_ecb, 1343: <<"04B915BA43FEB5B6">>, 1344: <<"42FD443059577FA2">>}, 1345: {aes_ecb, 1346: <<"0113B970FD34F2CE">>, 1347: <<"059B5E0851CF143A">>}, 1348: {aes_ecb, 1349: <<"0170F175468FB5E6">>, 1350: <<"0756D8E0774761D2">>}, 1351: {aes_ecb, 1352: <<"43297FAD38E373FE">>, 1353: <<"762514B829BF486A">>}, 1354: {aes_ecb, 1355: <<"07A7137045DA2A16">>, 1356: <<"3BDD119049372802">>}, 1357: {aes_ecb, 1358: <<"04689104C2FD3B2F">>, 1359: <<"26955F6835AF609A">>}, 1360: {aes_ecb, 1361: <<"37D06BB516CB7546">>, 1362: <<"164D5E404F275232">>}, 1363: {aes_ecb, 1364: <<"1F08260D1AC2465E">>, 1365: <<"6B056E18759F5CCA">>}, 1366: {aes_ecb, 1367: <<"584023641ABA6176">>, 1368: <<"004BD6EF09176062">>}, 1369: {aes_ecb, 1370: <<"025816164629B007">>, 1371: <<"480D39006EE762F2">>}, 1372: {aes_ecb, 1373: <<"49793EBC79B3258F">>, 1374: <<"437540C8698F3CFA">>}, 1375: {aes_ecb, 1376: <<"018310DC409B26D6">>, 1377: <<"1D9D5C5018F728C2">>}, 1378: {aes_ecb, 1379: <<"1C587F1C13924FEF">>, 1380: <<"305532286D6F295A">>}, 1381: {aes_ecb, 1382: <<"0101010101010101">>, 1383: <<"0123456789ABCDEF">>}, 1384: {aes_ecb, 1385: <<"1F1F1F1F0E0E0E0E">>, 1386: <<"0123456789ABCDEF">>}, 1387: {aes_ecb, 1388: <<"E0FEE0FEF1FEF1FE">>, 1389: <<"0123456789ABCDEF">>}, 1390: {aes_ecb, 1391: <<"0000000000000000">>, 1392: <<"FFFFFFFFFFFFFFFF">>}, 1393: {aes_ecb, 1394: <<"FFFFFFFFFFFFFFFF">>, 1395: <<"0000000000000000">>}, 1396: {aes_ecb, 1397: <<"0123456789ABCDEF">>, 1398: <<"0000000000000000">>}, 1399: {aes_ecb, 1400: <<"FEDCBA9876543210">>, 1401: <<"FFFFFFFFFFFFFFFF">>}, 1402: %% AES ECB test vectors from http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf 1403: %% F.1.1 ECB-AES128.Encrypt, F.1.2 ECB-AES128.Decrypt 1404: {aes_ecb, 1405: hexstr2bin("2b7e151628aed2a6abf7158809cf4f3c"), 1406: hexstr2bin("6bc1bee22e409f96e93d7e117393172a" 1407: "ae2d8a571e03ac9c9eb76fac45af8e51" 1408: "30c81c46a35ce411e5fbc1191a0a52ef" 1409: "f69f2445df4f9b17ad2b417be66c3710")}, 1410: %% F.1.3 ECB-AES192.Encrypt, F.1.4 ECB-AES192.Decrypt 1411: {aes_ecb, 1412: hexstr2bin("8e73b0f7da0e6452c810f32b809079e5" 1413: "62f8ead2522c6b7b"), 1414: hexstr2bin("6bc1bee22e409f96e93d7e117393172a" 1415: "ae2d8a571e03ac9c9eb76fac45af8e51" 1416: "30c81c46a35ce411e5fbc1191a0a52ef" 1417: "f69f2445df4f9b17ad2b417be66c3710")}, 1418: %% F.1.5 ECB-AES256.Encrypt, F.1.6 ECB-AES256.Decrypt 1419: {aes_ecb, 1420: hexstr2bin("603deb1015ca71be2b73aef0857d7781" 1421: "1f352c073b6108d72d9810a30914dff4"), 1422: hexstr2bin("6bc1bee22e409f96e93d7e117393172a" 1423: "ae2d8a571e03ac9c9eb76fac45af8e51" 1424: "30c81c46a35ce411e5fbc1191a0a52ef" 1425: "f69f2445df4f9b17ad2b417be66c3710")} 1426: ]. 1427: 1428: aes_ige256() -> 1429: [{aes_ige256, 1430: hexstr2bin("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"), 1431: hexstr2bin("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F"), 1432: hexstr2bin("6bc1bee22e409f96e93d7e117393172a")}, 1433: {aes_ige256, 1434: hexstr2bin("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"), 1435: hexstr2bin("4D0F9E735749215C05CB20DA00F7814B77D33F8A668BEBBAC1739AB20302D4FE"), 1436: hexstr2bin("ae2d8a571e03ac9c9eb76fac45af8e51")}, 1437: {aes_ige256, 1438: hexstr2bin("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"), 1439: hexstr2bin("2A5569424DAE1ACEABDEEA108DB4606AE21A9227CAB5F55BF52535CFA2B34717"), 1440: hexstr2bin("30c81c46a35ce411e5fbc1191a0a52ef")}, 1441: {aes_ige256, 1442: hexstr2bin("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"), 1443: hexstr2bin("15D5A583D2D668E518E683D9BDF1B6D0E0C3B1E5D5C1D51E964822E1ADE88DFA"), 1444: hexstr2bin("f69f2445df4f9b17ad2b417be66c3710")} 1445: ]. 1446: 1447: aes_cfb8() -> 1448: [{aes_cfb8, 1449: hexstr2bin("2b7e151628aed2a6abf7158809cf4f3c"), 1450: hexstr2bin("000102030405060708090a0b0c0d0e0f"), 1451: hexstr2bin("6bc1bee22e409f96e93d7e117393172a")}, 1452: {aes_cfb8, 1453: hexstr2bin("2b7e151628aed2a6abf7158809cf4f3c"), 1454: hexstr2bin("3B3FD92EB72DAD20333449F8E83CFB4A"), 1455: hexstr2bin("ae2d8a571e03ac9c9eb76fac45af8e51")}, 1456: {aes_cfb8, 1457: hexstr2bin("2b7e151628aed2a6abf7158809cf4f3c"), 1458: hexstr2bin("C8A64537A0B3A93FCDE3CDAD9F1CE58B"), 1459: hexstr2bin("30c81c46a35ce411e5fbc1191a0a52ef")}, 1460: {aes_cfb8, 1461: hexstr2bin("2b7e151628aed2a6abf7158809cf4f3c"), 1462: hexstr2bin("26751F67A3CBB140B1808CF187A4F4DF"), 1463: hexstr2bin("f69f2445df4f9b17ad2b417be66c3710")}, 1464: {aes_cfb8, 1465: hexstr2bin("8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b"), 1466: hexstr2bin("000102030405060708090a0b0c0d0e0f"), 1467: hexstr2bin("6bc1bee22e409f96e93d7e117393172a")}, 1468: {aes_cfb8, 1469: hexstr2bin("8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b"), 1470: hexstr2bin("cdc80d6fddf18cab34c25909c99a4174"), 1471: hexstr2bin("ae2d8a571e03ac9c9eb76fac45af8e51")}, 1472: {aes_cfb8, 1473: hexstr2bin("8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b"), 1474: hexstr2bin("67ce7f7f81173621961a2b70171d3d7a"), 1475: hexstr2bin("30c81c46a35ce411e5fbc1191a0a52ef")}, 1476: {aes_cfb8, 1477: hexstr2bin("8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b"), 1478: hexstr2bin("2e1e8a1dd59b88b1c8e60fed1efac4c9"), 1479: hexstr2bin("f69f2445df4f9b17ad2b417be66c3710")}, 1480: {aes_cfb8, 1481: hexstr2bin("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"), 1482: hexstr2bin("000102030405060708090a0b0c0d0e0f"), 1483: hexstr2bin("6bc1bee22e409f96e93d7e117393172a")}, 1484: {aes_cfb8, 1485: hexstr2bin("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"), 1486: hexstr2bin("dc7e84bfda79164b7ecd8486985d3860"), 1487: hexstr2bin("ae2d8a571e03ac9c9eb76fac45af8e51")}, 1488: {aes_cfb8, 1489: hexstr2bin("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"), 1490: hexstr2bin("39ffed143b28b1c832113c6331e5407b"), 1491: hexstr2bin("30c81c46a35ce411e5fbc1191a0a52ef")}, 1492: {aes_cfb8, 1493: hexstr2bin("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"), 1494: hexstr2bin("df10132415e54b92a13ed0a8267ae2f9"), 1495: hexstr2bin("f69f2445df4f9b17ad2b417be66c3710")} 1496: ]. 1497: 1498: aes_cfb128() -> 1499: [{aes_cfb128, 1500: hexstr2bin("2b7e151628aed2a6abf7158809cf4f3c"), 1501: hexstr2bin("000102030405060708090a0b0c0d0e0f"), 1502: hexstr2bin("6bc1bee22e409f96e93d7e117393172a")}, 1503: {aes_cfb128, 1504: hexstr2bin("2b7e151628aed2a6abf7158809cf4f3c"), 1505: hexstr2bin("3B3FD92EB72DAD20333449F8E83CFB4A"), 1506: hexstr2bin("ae2d8a571e03ac9c9eb76fac45af8e51")}, 1507: {aes_cfb128, 1508: hexstr2bin("2b7e151628aed2a6abf7158809cf4f3c"), 1509: hexstr2bin("C8A64537A0B3A93FCDE3CDAD9F1CE58B"), 1510: hexstr2bin("30c81c46a35ce411e5fbc1191a0a52ef")}, 1511: {aes_cfb128, 1512: hexstr2bin("2b7e151628aed2a6abf7158809cf4f3c"), 1513: hexstr2bin("26751F67A3CBB140B1808CF187A4F4DF"), 1514: hexstr2bin("f69f2445df4f9b17ad2b417be66c3710")}, 1515: {aes_cfb128, 1516: hexstr2bin("8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b"), 1517: hexstr2bin("000102030405060708090a0b0c0d0e0f"), 1518: hexstr2bin("6bc1bee22e409f96e93d7e117393172a")}, 1519: {aes_cfb128, 1520: hexstr2bin("8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b"), 1521: hexstr2bin("cdc80d6fddf18cab34c25909c99a4174"), 1522: hexstr2bin("ae2d8a571e03ac9c9eb76fac45af8e51")}, 1523: {aes_cfb128, 1524: hexstr2bin("8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b"), 1525: hexstr2bin("67ce7f7f81173621961a2b70171d3d7a"), 1526: hexstr2bin("30c81c46a35ce411e5fbc1191a0a52ef")}, 1527: {aes_cfb128, 1528: hexstr2bin("8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b"), 1529: hexstr2bin("2e1e8a1dd59b88b1c8e60fed1efac4c9"), 1530: hexstr2bin("f69f2445df4f9b17ad2b417be66c3710")}, 1531: {aes_cfb128, 1532: hexstr2bin("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"), 1533: hexstr2bin("000102030405060708090a0b0c0d0e0f"), 1534: hexstr2bin("6bc1bee22e409f96e93d7e117393172a")}, 1535: {aes_cfb128, 1536: hexstr2bin("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"), 1537: hexstr2bin("dc7e84bfda79164b7ecd8486985d3860"), 1538: hexstr2bin("ae2d8a571e03ac9c9eb76fac45af8e51")}, 1539: {aes_cfb128, 1540: hexstr2bin("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"), 1541: hexstr2bin("39ffed143b28b1c832113c6331e5407b"), 1542: hexstr2bin("30c81c46a35ce411e5fbc1191a0a52ef")}, 1543: {aes_cfb128, 1544: hexstr2bin("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"), 1545: hexstr2bin("df10132415e54b92a13ed0a8267ae2f9"), 1546: hexstr2bin("f69f2445df4f9b17ad2b417be66c3710")} 1547: ]. 1548: 1549: blowfish_cbc() -> 1550: [{blowfish_cbc, 1551: hexstr2bin("0123456789ABCDEFF0E1D2C3B4A59687"), 1552: hexstr2bin("FEDCBA9876543210"), 1553: hexstr2bin("37363534333231204E6F77206973207468652074696D6520666F722000000000") 1554: }]. 1555: 1556: blowfish_ecb() -> 1557: [ 1558: {blowfish_ecb, 1559: hexstr2bin("0000000000000000"), 1560: hexstr2bin("0000000000000000")}, 1561: {blowfish_ecb, 1562: hexstr2bin("FFFFFFFFFFFFFFFF"), 1563: hexstr2bin("FFFFFFFFFFFFFFFF")}, 1564: {blowfish_ecb, 1565: hexstr2bin("3000000000000000"), 1566: hexstr2bin("1000000000000001")}, 1567: {blowfish_ecb, 1568: hexstr2bin("1111111111111111"), 1569: hexstr2bin("1111111111111111")}, 1570: {blowfish_ecb, 1571: hexstr2bin("0123456789ABCDEF"), 1572: hexstr2bin("1111111111111111")}, 1573: {blowfish_ecb, 1574: hexstr2bin("0000000000000000"), 1575: hexstr2bin("0000000000000000")}, 1576: {blowfish_ecb, 1577: hexstr2bin("FEDCBA9876543210"), 1578: hexstr2bin("0123456789ABCDEF")}, 1579: {blowfish_ecb, 1580: hexstr2bin("7CA110454A1A6E57"), 1581: hexstr2bin("01A1D6D039776742")}, 1582: {blowfish_ecb, 1583: hexstr2bin("0131D9619DC1376E"), 1584: hexstr2bin("5CD54CA83DEF57DA")}, 1585: {blowfish_ecb, 1586: hexstr2bin("07A1133E4A0B2686"), 1587: hexstr2bin("0248D43806F67172")}, 1588: {blowfish_ecb, 1589: hexstr2bin("3849674C2602319E"), 1590: hexstr2bin("51454B582DDF440A")}, 1591: {blowfish_ecb, 1592: hexstr2bin("04B915BA43FEB5B6"), 1593: hexstr2bin("42FD443059577FA2")}, 1594: {blowfish_ecb, 1595: hexstr2bin("0113B970FD34F2CE"), 1596: hexstr2bin("059B5E0851CF143A")}, 1597: {blowfish_ecb, 1598: hexstr2bin("0170F175468FB5E6"), 1599: hexstr2bin("0756D8E0774761D2")}, 1600: {blowfish_ecb, 1601: hexstr2bin("43297FAD38E373FE"), 1602: hexstr2bin("762514B829BF486A")}, 1603: {blowfish_ecb, 1604: hexstr2bin("07A7137045DA2A16"), 1605: hexstr2bin("3BDD119049372802")}, 1606: {blowfish_ecb, 1607: hexstr2bin("04689104C2FD3B2F"), 1608: hexstr2bin("26955F6835AF609A")}, 1609: {blowfish_ecb, 1610: hexstr2bin("37D06BB516CB7546"), 1611: hexstr2bin("164D5E404F275232")}, 1612: {blowfish_ecb, 1613: hexstr2bin("1F08260D1AC2465E"), 1614: hexstr2bin("6B056E18759F5CCA")}, 1615: {blowfish_ecb, 1616: hexstr2bin("584023641ABA6176"), 1617: hexstr2bin("004BD6EF09176062")}, 1618: {blowfish_ecb, 1619: hexstr2bin("025816164629B007"), 1620: hexstr2bin("480D39006EE762F2")}, 1621: {blowfish_ecb, 1622: hexstr2bin("49793EBC79B3258F"), 1623: hexstr2bin("437540C8698F3CFA")}, 1624: {blowfish_ecb, 1625: hexstr2bin("018310DC409B26D6"), 1626: hexstr2bin("1D9D5C5018F728C2")}, 1627: {blowfish_ecb, 1628: hexstr2bin("1C587F1C13924FEF"), 1629: hexstr2bin("305532286D6F295A")}, 1630: {blowfish_ecb, 1631: hexstr2bin("0101010101010101"), 1632: hexstr2bin("0123456789ABCDEF")}, 1633: {blowfish_ecb, 1634: hexstr2bin("1F1F1F1F0E0E0E0E"), 1635: hexstr2bin("0123456789ABCDEF")}, 1636: {blowfish_ecb, 1637: hexstr2bin("E0FEE0FEF1FEF1FE"), 1638: hexstr2bin("0123456789ABCDEF")}, 1639: {blowfish_ecb, 1640: hexstr2bin("0000000000000000"), 1641: hexstr2bin("FFFFFFFFFFFFFFFF")}, 1642: {blowfish_ecb, 1643: hexstr2bin("FFFFFFFFFFFFFFFF"), 1644: hexstr2bin("0000000000000000")}, 1645: {blowfish_ecb, 1646: hexstr2bin("0123456789ABCDEF"), 1647: hexstr2bin("0000000000000000")}, 1648: {blowfish_ecb, 1649: hexstr2bin("FEDCBA9876543210"), 1650: hexstr2bin("FFFFFFFFFFFFFFFF")} 1651: ]. 1652: 1653: blowfish_cfb64() -> 1654: [{blowfish_cfb64, 1655: hexstr2bin("0123456789ABCDEFF0E1D2C3B4A59687"), 1656: hexstr2bin("FEDCBA9876543210"), 1657: hexstr2bin("37363534333231204E6F77206973207468652074696D6520666F722000") 1658: }]. 1659: blowfish_ofb64() -> 1660: [{blowfish_ofb64, 1661: hexstr2bin("0123456789ABCDEFF0E1D2C3B4A59687"), 1662: hexstr2bin("FEDCBA9876543210"), 1663: hexstr2bin("37363534333231204E6F77206973207468652074696D6520666F722000") 1664: }]. 1665: 1666: rc4() -> 1667: [{rc4, <<"apaapa">>, <<"Yo baby yo">>}, 1668: {rc4, <<"apaapa">>, list_to_binary(lists:seq(0, 255))}, 1669: {rc4, <<"apaapa">>, long_msg()} 1670: ]. 1671: 1672: aes_ctr() -> 1673: [ %% F.5.3 CTR-AES192.Encrypt 1674: {aes_ctr, hexstr2bin("2b7e151628aed2a6abf7158809cf4f3c"), 1675: hexstr2bin("f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff"), 1676: hexstr2bin("6bc1bee22e409f96e93d7e117393172a")}, 1677: {aes_ctr, hexstr2bin("2b7e151628aed2a6abf7158809cf4f3c"), 1678: hexstr2bin("f0f1f2f3f4f5f6f7f8f9fafbfcfdff00"), 1679: hexstr2bin("ae2d8a571e03ac9c9eb76fac45af8e51")}, 1680: {aes_ctr, hexstr2bin("2b7e151628aed2a6abf7158809cf4f3c"), 1681: hexstr2bin("f0f1f2f3f4f5f6f7f8f9fafbfcfdff01"), 1682: hexstr2bin("30c81c46a35ce411e5fbc1191a0a52ef") }, 1683: {aes_ctr, hexstr2bin("2b7e151628aed2a6abf7158809cf4f3c"), 1684: hexstr2bin("f0f1f2f3f4f5f6f7f8f9fafbfcfdff02"), 1685: hexstr2bin("f69f2445df4f9b17ad2b417be66c3710")}, 1686: 1687: %% F.5.3 CTR-AES192.Encrypt 1688: {aes_ctr, hexstr2bin("8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b"), 1689: hexstr2bin("f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff"), 1690: hexstr2bin("6bc1bee22e409f96e93d7e117393172a")}, 1691: {aes_ctr, hexstr2bin("8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b"), 1692: hexstr2bin("f0f1f2f3f4f5f6f7f8f9fafbfcfdff00"), 1693: hexstr2bin("ae2d8a571e03ac9c9eb76fac45af8e51")}, 1694: {aes_ctr, hexstr2bin("8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b"), 1695: hexstr2bin("f0f1f2f3f4f5f6f7f8f9fafbfcfdff01"), 1696: hexstr2bin("30c81c46a35ce411e5fbc1191a0a52ef")}, 1697: {aes_ctr, hexstr2bin("8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b"), 1698: hexstr2bin("f0f1f2f3f4f5f6f7f8f9fafbfcfdff02"), 1699: hexstr2bin("f69f2445df4f9b17ad2b417be66c3710")}, 1700: 1701: %% F.5.5 CTR-AES256.Encrypt 1702: {aes_ctr, hexstr2bin("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"), 1703: hexstr2bin("f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff"), 1704: hexstr2bin("6bc1bee22e409f96e93d7e117393172a")}, 1705: {aes_ctr, hexstr2bin("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"), 1706: hexstr2bin("f0f1f2f3f4f5f6f7f8f9fafbfcfdff00"), 1707: hexstr2bin("ae2d8a571e03ac9c9eb76fac45af8e51")}, 1708: {aes_ctr, hexstr2bin("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"), 1709: hexstr2bin("f0f1f2f3f4f5f6f7f8f9fafbfcfdff01"), 1710: hexstr2bin("30c81c46a35ce411e5fbc1191a0a52ef")}, 1711: {aes_ctr, hexstr2bin("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"), 1712: hexstr2bin("f0f1f2f3f4f5f6f7f8f9fafbfcfdff02"), 1713: hexstr2bin("f69f2445df4f9b17ad2b417be66c3710")}, 1714: 1715: {aes_ctr, hexstr2bin("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"), 1716: hexstr2bin("f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff"), 1717: long_msg()} 1718: ]. 1719: 1720: 1721: %% AES GCM test vectors from http://csrc.nist.gov/groups/ST/toolkit/BCM/documents/proposedmodes/gcm/gcm-spec.pdf 1722: aes_gcm() -> 1723: [ 1724: %% Test Case 1 1725: {aes_gcm, hexstr2bin("00000000000000000000000000000000"), %% Key 1726: hexstr2bin(""), %% PlainText 1727: hexstr2bin("000000000000000000000000"), %% IV 1728: hexstr2bin(""), %% AAD 1729: hexstr2bin(""), %% CipherText 1730: hexstr2bin("58e2fccefa7e3061367f1d57a4e7455a")}, %% CipherTag 1731: 1732: %% Test Case 2 1733: {aes_gcm, hexstr2bin("00000000000000000000000000000000"), %% Key 1734: hexstr2bin("00000000000000000000000000000000"), %% PlainText 1735: hexstr2bin("000000000000000000000000"), %% IV 1736: hexstr2bin(""), %% AAD 1737: hexstr2bin("0388dace60b6a392f328c2b971b2fe78"), %% CipherText 1738: hexstr2bin("ab6e47d42cec13bdf53a67b21257bddf")}, %% CipherTag 1739: 1740: %% Test Case 3 1741: {aes_gcm, hexstr2bin("feffe9928665731c6d6a8f9467308308"), %% Key 1742: hexstr2bin("d9313225f88406e5a55909c5aff5269a" %% PlainText 1743: "86a7a9531534f7da2e4c303d8a318a72" 1744: "1c3c0c95956809532fcf0e2449a6b525" 1745: "b16aedf5aa0de657ba637b391aafd255"), 1746: hexstr2bin("cafebabefacedbaddecaf888"), %% IV 1747: hexstr2bin(""), %% AAD 1748: hexstr2bin("42831ec2217774244b7221b784d0d49c" %% CipherText 1749: "e3aa212f2c02a4e035c17e2329aca12e" 1750: "21d514b25466931c7d8f6a5aac84aa05" 1751: "1ba30b396a0aac973d58e091473f5985"), 1752: hexstr2bin("4d5c2af327cd64a62cf35abd2ba6fab4")}, %% CipherTag 1753: 1754: %% Test Case 4 1755: {aes_gcm, hexstr2bin("feffe9928665731c6d6a8f9467308308"), %% Key 1756: hexstr2bin("d9313225f88406e5a55909c5aff5269a" %% PlainText 1757: "86a7a9531534f7da2e4c303d8a318a72" 1758: "1c3c0c95956809532fcf0e2449a6b525" 1759: "b16aedf5aa0de657ba637b39"), 1760: hexstr2bin("cafebabefacedbaddecaf888"), %% IV 1761: hexstr2bin("feedfacedeadbeeffeedfacedeadbeef" %% AAD 1762: "abaddad2"), 1763: hexstr2bin("42831ec2217774244b7221b784d0d49c" %% CipherText 1764: "e3aa212f2c02a4e035c17e2329aca12e" 1765: "21d514b25466931c7d8f6a5aac84aa05" 1766: "1ba30b396a0aac973d58e091"), 1767: hexstr2bin("5bc94fbc3221a5db94fae95ae7121a47")}, %% CipherTag 1768: 1769: %% Test Case 5 1770: {aes_gcm, hexstr2bin("feffe9928665731c6d6a8f9467308308"), %% Key 1771: hexstr2bin("d9313225f88406e5a55909c5aff5269a" %% PlainText 1772: "86a7a9531534f7da2e4c303d8a318a72" 1773: "1c3c0c95956809532fcf0e2449a6b525" 1774: "b16aedf5aa0de657ba637b39"), 1775: hexstr2bin("cafebabefacedbad"), %% IV 1776: hexstr2bin("feedfacedeadbeeffeedfacedeadbeef" %% AAD 1777: "abaddad2"), 1778: hexstr2bin("61353b4c2806934a777ff51fa22a4755" %% CipherText 1779: "699b2a714fcdc6f83766e5f97b6c7423" 1780: "73806900e49f24b22b097544d4896b42" 1781: "4989b5e1ebac0f07c23f4598"), 1782: hexstr2bin("3612d2e79e3b0785561be14aaca2fccb")}, %% CipherTag 1783: 1784: %% Test Case 6" 1785: {aes_gcm, hexstr2bin("feffe9928665731c6d6a8f9467308308"), %% Key 1786: hexstr2bin("d9313225f88406e5a55909c5aff5269a" %% PlainText 1787: "86a7a9531534f7da2e4c303d8a318a72" 1788: "1c3c0c95956809532fcf0e2449a6b525" 1789: "b16aedf5aa0de657ba637b39"), 1790: hexstr2bin("9313225df88406e555909c5aff5269aa" %% IV 1791: "6a7a9538534f7da1e4c303d2a318a728" 1792: "c3c0c95156809539fcf0e2429a6b5254" 1793: "16aedbf5a0de6a57a637b39b"), 1794: hexstr2bin("feedfacedeadbeeffeedfacedeadbeef" %% AAD 1795: "abaddad2"), 1796: hexstr2bin("8ce24998625615b603a033aca13fb894" %% CipherText 1797: "be9112a5c3a211a8ba262a3cca7e2ca7" 1798: "01e4a9a4fba43c90ccdcb281d48c7c6f" 1799: "d62875d2aca417034c34aee5"), 1800: hexstr2bin("619cc5aefffe0bfa462af43c1699d050")}, %% CipherTag 1801: 1802: %% Test Case 7 1803: {aes_gcm, hexstr2bin("00000000000000000000000000000000" %% Key 1804: "0000000000000000"), 1805: hexstr2bin(""), %% PlainText 1806: hexstr2bin("000000000000000000000000"), %% IV 1807: hexstr2bin(""), %% AAD 1808: hexstr2bin(""), %% CipherText 1809: hexstr2bin("cd33b28ac773f74ba00ed1f312572435")}, %% CipherTag 1810: 1811: %% Test Case 8 1812: {aes_gcm, hexstr2bin("00000000000000000000000000000000" %% Key 1813: "0000000000000000"), 1814: hexstr2bin("00000000000000000000000000000000"), %% PlainText 1815: hexstr2bin("000000000000000000000000"), %% IV 1816: hexstr2bin(""), %% AAD 1817: hexstr2bin("98e7247c07f0fe411c267e4384b0f600"), %% CipherText 1818: hexstr2bin("2ff58d80033927ab8ef4d4587514f0fb")}, %% CipherTag 1819: 1820: %% Test Case 9 1821: {aes_gcm, hexstr2bin("feffe9928665731c6d6a8f9467308308" %% Key 1822: "feffe9928665731c"), 1823: hexstr2bin("d9313225f88406e5a55909c5aff5269a" %% PlainText 1824: "86a7a9531534f7da2e4c303d8a318a72" 1825: "1c3c0c95956809532fcf0e2449a6b525" 1826: "b16aedf5aa0de657ba637b391aafd255"), 1827: hexstr2bin("cafebabefacedbaddecaf888"), %% IV 1828: hexstr2bin(""), %% ADD 1829: hexstr2bin("3980ca0b3c00e841eb06fac4872a2757" %% CipherText 1830: "859e1ceaa6efd984628593b40ca1e19c" 1831: "7d773d00c144c525ac619d18c84a3f47" 1832: "18e2448b2fe324d9ccda2710acade256"), 1833: hexstr2bin("9924a7c8587336bfb118024db8674a14")}, %% CipherTag 1834: 1835: %% Test Case 10 1836: {aes_gcm, hexstr2bin("feffe9928665731c6d6a8f9467308308" %% Key 1837: "feffe9928665731c"), 1838: hexstr2bin("d9313225f88406e5a55909c5aff5269a" %% PlainText 1839: "86a7a9531534f7da2e4c303d8a318a72" 1840: "1c3c0c95956809532fcf0e2449a6b525" 1841: "b16aedf5aa0de657ba637b39"), 1842: hexstr2bin("cafebabefacedbaddecaf888"), %% IV 1843: hexstr2bin("feedfacedeadbeeffeedfacedeadbeef" %% AAD 1844: "abaddad2"), 1845: hexstr2bin("3980ca0b3c00e841eb06fac4872a2757" %% CipherText 1846: "859e1ceaa6efd984628593b40ca1e19c" 1847: "7d773d00c144c525ac619d18c84a3f47" 1848: "18e2448b2fe324d9ccda2710"), 1849: hexstr2bin("2519498e80f1478f37ba55bd6d27618c")}, %% CipherTag 1850: 1851: %% Test Case 11 1852: {aes_gcm, hexstr2bin("feffe9928665731c6d6a8f9467308308" %% Key 1853: "feffe9928665731c"), 1854: hexstr2bin("d9313225f88406e5a55909c5aff5269a" %% PlainText 1855: "86a7a9531534f7da2e4c303d8a318a72" 1856: "1c3c0c95956809532fcf0e2449a6b525" 1857: "b16aedf5aa0de657ba637b39"), 1858: hexstr2bin("cafebabefacedbad"), %% IV 1859: hexstr2bin("feedfacedeadbeeffeedfacedeadbeef" %% AAD 1860: "abaddad2"), 1861: hexstr2bin("0f10f599ae14a154ed24b36e25324db8" %% CipherText 1862: "c566632ef2bbb34f8347280fc4507057" 1863: "fddc29df9a471f75c66541d4d4dad1c9" 1864: "e93a19a58e8b473fa0f062f7"), 1865: hexstr2bin("65dcc57fcf623a24094fcca40d3533f8")}, %% CipherTag 1866: 1867: %% Test Case 12 1868: {aes_gcm, hexstr2bin("feffe9928665731c6d6a8f9467308308" %% Key 1869: "feffe9928665731c"), 1870: hexstr2bin("d9313225f88406e5a55909c5aff5269a" %% PlainText 1871: "86a7a9531534f7da2e4c303d8a318a72" 1872: "1c3c0c95956809532fcf0e2449a6b525" 1873: "b16aedf5aa0de657ba637b39"), 1874: hexstr2bin("9313225df88406e555909c5aff5269aa" %% IV 1875: "6a7a9538534f7da1e4c303d2a318a728" 1876: "c3c0c95156809539fcf0e2429a6b5254" 1877: "16aedbf5a0de6a57a637b39b"), 1878: hexstr2bin("feedfacedeadbeeffeedfacedeadbeef" %% AAD 1879: "abaddad2"), 1880: hexstr2bin("d27e88681ce3243c4830165a8fdcf9ff" %% CipherText 1881: "1de9a1d8e6b447ef6ef7b79828666e45" 1882: "81e79012af34ddd9e2f037589b292db3" 1883: "e67c036745fa22e7e9b7373b"), 1884: hexstr2bin("dcf566ff291c25bbb8568fc3d376a6d9")}, %% CipherTag 1885: 1886: %% Test Case 13 1887: {aes_gcm, hexstr2bin("00000000000000000000000000000000" %% Key 1888: "00000000000000000000000000000000"), 1889: hexstr2bin(""), %% PlainText 1890: hexstr2bin("000000000000000000000000"), %% IV 1891: hexstr2bin(""), %% AAD 1892: hexstr2bin(""), %% CipherText 1893: hexstr2bin("530f8afbc74536b9a963b4f1c4cb738b")}, %% CipherTag 1894: 1895: %% Test Case 14 1896: {aes_gcm, hexstr2bin("00000000000000000000000000000000" %% Key 1897: "00000000000000000000000000000000"), 1898: hexstr2bin("00000000000000000000000000000000"), %% PlainText 1899: hexstr2bin("000000000000000000000000"), %% IV 1900: hexstr2bin(""), %% AAD 1901: hexstr2bin("cea7403d4d606b6e074ec5d3baf39d18"), %% CipherText 1902: hexstr2bin("d0d1c8a799996bf0265b98b5d48ab919")}, %% CipherTag 1903: 1904: %% Test Case 15 1905: {aes_gcm, hexstr2bin("feffe9928665731c6d6a8f9467308308" %% Key 1906: "feffe9928665731c6d6a8f9467308308"), 1907: hexstr2bin("d9313225f88406e5a55909c5aff5269a" %% PlainText 1908: "86a7a9531534f7da2e4c303d8a318a72" 1909: "1c3c0c95956809532fcf0e2449a6b525" 1910: "b16aedf5aa0de657ba637b391aafd255"), 1911: hexstr2bin("cafebabefacedbaddecaf888"), %% IV 1912: hexstr2bin(""), %% AAD 1913: hexstr2bin("522dc1f099567d07f47f37a32a84427d" %% CipherText 1914: "643a8cdcbfe5c0c97598a2bd2555d1aa" 1915: "8cb08e48590dbb3da7b08b1056828838" 1916: "c5f61e6393ba7a0abcc9f662898015ad"), 1917: hexstr2bin("b094dac5d93471bdec1a502270e3cc6c")}, %% CipherTag 1918: 1919: %% Test Case 16 1920: {aes_gcm, hexstr2bin("feffe9928665731c6d6a8f9467308308" %% Key 1921: "feffe9928665731c6d6a8f9467308308"), 1922: hexstr2bin("d9313225f88406e5a55909c5aff5269a" %% PlainText 1923: "86a7a9531534f7da2e4c303d8a318a72" 1924: "1c3c0c95956809532fcf0e2449a6b525" 1925: "b16aedf5aa0de657ba637b39"), 1926: hexstr2bin("cafebabefacedbaddecaf888"), %% IV 1927: hexstr2bin("feedfacedeadbeeffeedfacedeadbeef" %% AAD 1928: "abaddad2"), 1929: hexstr2bin("522dc1f099567d07f47f37a32a84427d" %% CipherText 1930: "643a8cdcbfe5c0c97598a2bd2555d1aa" 1931: "8cb08e48590dbb3da7b08b1056828838" 1932: "c5f61e6393ba7a0abcc9f662"), 1933: hexstr2bin("76fc6ece0f4e1768cddf8853bb2d551b")}, %% CipherTag 1934: 1935: %% Test Case 17 1936: {aes_gcm, hexstr2bin("feffe9928665731c6d6a8f9467308308" %% Key 1937: "feffe9928665731c6d6a8f9467308308"), 1938: hexstr2bin("d9313225f88406e5a55909c5aff5269a" %% PlainText 1939: "86a7a9531534f7da2e4c303d8a318a72" 1940: "1c3c0c95956809532fcf0e2449a6b525" 1941: "b16aedf5aa0de657ba637b39"), 1942: hexstr2bin("cafebabefacedbad"), %% IV 1943: hexstr2bin("feedfacedeadbeeffeedfacedeadbeef" %% AAD 1944: "abaddad2"), 1945: hexstr2bin("c3762df1ca787d32ae47c13bf19844cb" %% CipherText 1946: "af1ae14d0b976afac52ff7d79bba9de0" 1947: "feb582d33934a4f0954cc2363bc73f78" 1948: "62ac430e64abe499f47c9b1f"), 1949: hexstr2bin("3a337dbf46a792c45e454913fe2ea8f2")}, %% CipherTag 1950: 1951: %% Test Case 18 1952: {aes_gcm, hexstr2bin("feffe9928665731c6d6a8f9467308308" %% Key 1953: "feffe9928665731c6d6a8f9467308308"), 1954: hexstr2bin("d9313225f88406e5a55909c5aff5269a" %% PlainText 1955: "86a7a9531534f7da2e4c303d8a318a72" 1956: "1c3c0c95956809532fcf0e2449a6b525" 1957: "b16aedf5aa0de657ba637b39"), 1958: hexstr2bin("9313225df88406e555909c5aff5269aa" %% IV 1959: "6a7a9538534f7da1e4c303d2a318a728" 1960: "c3c0c95156809539fcf0e2429a6b5254" 1961: "16aedbf5a0de6a57a637b39b"), 1962: hexstr2bin("feedfacedeadbeeffeedfacedeadbeef" %% AAD 1963: "abaddad2"), 1964: hexstr2bin("5a8def2f0c9e53f1f75d7853659e2a20" %% CipherText 1965: "eeb2b22aafde6419a058ab4f6f746bf4" 1966: "0fc0c3b780f244452da3ebf1c5d82cde" 1967: "a2418997200ef82e44ae7e3f"), 1968: hexstr2bin("a44a8266ee1c8eb0c8b5d4cf5ae9f19a")}, %% CipherTag 1969: 1970: %% Test Case 0 for TagLength = 1 1971: {aes_gcm, hexstr2bin("00000000000000000000000000000000"), %% Key 1972: hexstr2bin(""), %% PlainText 1973: hexstr2bin("000000000000000000000000"), %% IV 1974: hexstr2bin(""), %% AAD 1975: hexstr2bin(""), %% CipherText 1976: hexstr2bin("58"), %% CipherTag 1977: 1}, %% TagLength 1978: 1979: %% Test Case 18 for TagLength = 1 1980: {aes_gcm, hexstr2bin("feffe9928665731c6d6a8f9467308308" %% Key 1981: "feffe9928665731c6d6a8f9467308308"), 1982: hexstr2bin("d9313225f88406e5a55909c5aff5269a" %% PlainText 1983: "86a7a9531534f7da2e4c303d8a318a72" 1984: "1c3c0c95956809532fcf0e2449a6b525" 1985: "b16aedf5aa0de657ba637b39"), 1986: hexstr2bin("9313225df88406e555909c5aff5269aa" %% IV 1987: "6a7a9538534f7da1e4c303d2a318a728" 1988: "c3c0c95156809539fcf0e2429a6b5254" 1989: "16aedbf5a0de6a57a637b39b"), 1990: hexstr2bin("feedfacedeadbeeffeedfacedeadbeef" %% AAD 1991: "abaddad2"), 1992: hexstr2bin("5a8def2f0c9e53f1f75d7853659e2a20" %% CipherText 1993: "eeb2b22aafde6419a058ab4f6f746bf4" 1994: "0fc0c3b780f244452da3ebf1c5d82cde" 1995: "a2418997200ef82e44ae7e3f"), 1996: hexstr2bin("a4"), %% CipherTag 1997: 1} %% TagLength 1998: ]. 1999: 2000: %% http://tools.ietf.org/html/draft-agl-tls-chacha20poly1305-04 2001: chacha20_poly1305() -> 2002: [ 2003: {chacha20_poly1305, hexstr2bin("4290bcb154173531f314af57f3be3b500" %% Key 2004: "6da371ece272afa1b5dbdd1100a1007"), 2005: hexstr2bin("86d09974840bded2a5ca"), %% PlainText 2006: hexstr2bin("cd7cf67be39c794a"), %% Nonce 2007: hexstr2bin("87e229d4500845a079c0"), %% AAD 2008: hexstr2bin("e3e446f7ede9a19b62a4"), %% CipherText 2009: hexstr2bin("677dabf4e3d24b876bb284753896e1d6")} %% CipherTag 2010: ]. 2011: 2012: rsa_plain() -> 2013: <<"7896345786348756234 Hejsan Svejsan, erlang crypto debugger" 2014: "09812312908312378623487263487623412039812 huagasd">>. 2015: rsa_public() -> 2016: [65537, 7919488123861148172698919999061127847747888703039837999377650217570191053151807772962118671509138346758471459464133273114654252861270845708312601272799123]. 2017: rsa_private() -> 2018: rsa_public() ++ [7531712708607620783801185371644749935066152052780368689827275932079815492940396744378735701395659435842364793962992309884847527234216715366607660219930945]. 2019: 2020: rsa_public_stronger() -> 2021: [65537, 24629450921918866883077380602720734920775458960049554761386137065662137652635369332143446151320538248280934442179850504891395344346514465469955766163141133564033962851182759993807898821114734943339732032639891483186089941567854227407119560631150779000222837755424893038740314247760600374970909894211201220612920040986106639419467243909950276018045907029941478599124238353052062083560294570722081552510960894164859765695309596889747541376908786225647625736062865138957717982693312699025417086612046330464651009693307624955796202070510577399561730651967517158452930742355327167632521808183383868100102455048819375344881]. 2022: 2023: rsa_private_stronger() -> 2024: rsa_public_stronger() ++ [13565232776562604620467234237694854016819673873109064019820773052201665024482754648718278717031083946624786145611240731564761987114634269887293030432042088547345315212418830656522115993209293567218379960177754901461542373481136856927955012596579314262051109321754382091434920473734937991286600905464814063189230779981494358415076362038786197620360127262110530926733754185204773610295221669711309000953136320804528874719105049753061737780710448207922456570922652651354760939379096788728229638142403068102990416717272880560951246813789730402978652924934794503277969128609831043469924881848849409122972426787999886557185]. 2025: 2026: dss_plain() -> 2027: rsa_plain(). 2028: dss_public() -> 2029: 25854665488880835237281628794585130313500176551981812527054397586638455298000483144002221850980183404910190346416063318160497344811383498859129095184158800144312512447497510551471331451396405348497845813002058423110442376886564659959543650802132345311573634832461635601376738282831340827591903548964194832978. 2030: dss_private() -> 2031: 441502407453038284293378221372000880210588566361. 2032: dss_params() -> 2033: [109799869232806890760655301608454668257695818999841877165019612946154359052535682480084145133201304812979481136659521529774182959764860329095546511521488413513097576425638476458000255392402120367876345280670101492199681798674053929238558140260669578407351853803102625390950534052428162468100618240968893110797, 2034: 1349199015905534965792122312016505075413456283393, 2035: 18320614775012672475365915366944922415598782131828709277168615511695849821411624805195787607930033958243224786899641459701930253094446221381818858674389863050420226114787005820357372837321561754462061849169568607689530279303056075793886577588606958623645901271866346406773590024901668622321064384483571751669]. 2036: 2037: ec_key_named() -> 2038: Curve = hd(crypto:ec_curves()), 2039: {D2_pub, D2_priv} = crypto:generate_key(ecdh, Curve), 2040: {[D2_priv, Curve], [D2_pub, Curve]}. 2041: 2042: ec_msg() -> 2043: <<99,234,6,64,190,237,201,99,80,248,58,40,70,45,149,218,5,246,242,63>>. 2044: 2045: srp3() -> 2046: Username = <<"alice">>, 2047: Password = <<"password123">>, 2048: Salt = hexstr2bin("2857827A19266A1F2BC6"), 2049: Prime = hexstr2bin("EEAF0AB9ADB38DD69C33F80AFA8FC5E86072618775FF3C0B9EA2314C" 2050: "9C256576D674DF7496EA81D3383B4813D692C6E0E0D5D8E250B98BE4" 2051: "8E495C1D6089DAD15DC7D7B46154D6B6CE8EF4AD69B15D4982559B29" 2052: "7BCF1885C529F566660E57EC68EDBC3C05726CC02FD4CBF4976EAA9A" 2053: "FD5138FE8376435B9FC61D2FC0EB06E3"), 2054: Generator = <<2>>, 2055: Version = '3', 2056: Scrambler = hexstr2bin("02E2476A"), 2057: 2058: %% X = hexstr2bin("96E54AB0CD4C5123EDCFA4A1502918AAD3C9E2A8"), 2059: Verifier = hexstr2bin("96EB5F13621D911AA1CA405DE9C64217D4108EEEECAFFE500034FE0E" 2060: "C031E42C8714667C161BCE0E7996F7DDE1B63824C130D2D7286C08C0" 2061: "49758420735961347112AE102A3F23B3F687F8FEE0DF2BFAF933C608" 2062: "D6FE5B5EEE3116FE54016E065BF8E8C9FDBBC08719231AC215149140" 2063: "519E8FDD9AA4F410C28A58AF42974D2D"), 2064: ClientPrivate = hexstr2bin("6411DE75538BED8170677D577D0608F39112BC95B503C447EB6AC945" 2065: "49C75C7B"), 2066: ServerPrivate = hexstr2bin("85E44A6F694DBE676145DB245A045CD37C99F05C562C7840A31F270D" 2067: "9AADCF8B"), 2068: ClientPublic = hexstr2bin("B22B1FFA2244B8CB94F3A9080F419CAEAB0DBA93EA1965B5E84587EE" 2069: "55C79E7A118865DC59B9D0353362C2A8261E7C1B0D221A0E233C2AD1" 2070: "640DACBB8664CBC9733EAC392DA7800142860380C3FC573C3C064329" 2071: "CF54063FD114C7210E9CB3A611EA8002B1844B698F930D95D143899B" 2072: "948A090E0C25938E5F84067D1883DC63"), 2073: ServerPublic = hexstr2bin("93A8C4D8B7F7395ADCFD4ABA37B015124513D3F37B3E85EB23064BE5" 2074: "F53C0AE32FFB9D8C0AA0DCFFA74D632DD67DEBB5C35AAE9812286CC8" 2075: "C43CC176ECBC6D3F447594D9554E995B2509127BF88FADDDA4982D03" 2076: "8EC3001320712D3B1269308CE70F319B2295FA57674F03A2D993CFB1" 2077: "F84C35B7D0C012FA73CD4C8F7D5A71C7"), 2078: 2079: SessionKey = hexstr2bin("C29A986C4D521BBC66428ED11D994CD7431574A6184B83CDCC345092" 2080: "791E75748A1D38CAC4BD14760F0D2694B711236419240FF2F172454C" 2081: "46ABF4FF39498DAFDD2C82924F7D7BD76CDFCE688C77D93F18A65409" 2082: "9176A9192615DC0277AE7C12F1F6A7F6563FCA11675D809AF578BDE5" 2083: "2B51E05D440B63099A017A0B45044801"), 2084: UserPassHash = crypto:hash(sha, [Salt, crypto:hash(sha, [Username, <<$:>>, Password])]), 2085: Verifier = crypto:mod_pow(Generator, UserPassHash, Prime), 2086: ClientPublic = crypto:mod_pow(Generator, ClientPrivate, Prime), 2087: srp(ClientPrivate, Generator, Prime, Version, Verifier, ServerPublic, ServerPrivate, UserPassHash, Scrambler, SessionKey). 2088: 2089: srp6() -> 2090: Username = <<"alice">>, 2091: Password = <<"password123">>, 2092: Salt = hexstr2bin("2857827A19266A1F2BC6"), 2093: Prime = hexstr2bin("EEAF0AB9ADB38DD69C33F80AFA8FC5E86072618775FF3C0B9EA2314C" 2094: "9C256576D674DF7496EA81D3383B4813D692C6E0E0D5D8E250B98BE4" 2095: "8E495C1D6089DAD15DC7D7B46154D6B6CE8EF4AD69B15D4982559B29" 2096: "7BCF1885C529F566660E57EC68EDBC3C05726CC02FD4CBF4976EAA9A" 2097: "FD5138FE8376435B9FC61D2FC0EB06E3"), 2098: Generator = <<2>>, 2099: Version = '6', 2100: Scrambler = hexstr2bin("0A2534C0BF52A0DA9001EEC62CF2A546AB0908A7"), 2101: Verifier = hexstr2bin("96EB5F13621D911AA1CA405DE9C64217D4108EEEECAFFE500034FE0E" 2102: "C031E42C8714667C161BCE0E7996F7DDE1B63824C130D2D7286C08C0" 2103: "49758420735961347112AE102A3F23B3F687F8FEE0DF2BFAF933C608" 2104: "D6FE5B5EEE3116FE54016E065BF8E8C9FDBBC08719231AC215149140" 2105: "519E8FDD9AA4F410C28A58AF42974D2D"), 2106: ClientPrivate = hexstr2bin("6411DE75538BED8170677D577D0608F39112BC95B503C447EB6AC945" 2107: "49C75C7B"), 2108: ServerPrivate = hexstr2bin("85E44A6F694DBE676145DB245A045CD37C99F05C562C7840A31F270D" 2109: "9AADCF8B"), 2110: ClientPublic = hexstr2bin("B22B1FFA2244B8CB94F3A9080F419CAEAB0DBA93EA1965B5E84587EE" 2111: "55C79E7A118865DC59B9D0353362C2A8261E7C1B0D221A0E233C2AD1" 2112: "640DACBB8664CBC9733EAC392DA7800142860380C3FC573C3C064329" 2113: "CF54063FD114C7210E9CB3A611EA8002B1844B698F930D95D143899B" 2114: "948A090E0C25938E5F84067D1883DC63"), 2115: ServerPublic = hexstr2bin("D2D07845CE7ECDB9845DD36B10ACD3598CC29049DE9F467F84CE16B6" 2116: "D97A6DC567AF8B0F9FEDF74962400AD5C357951E64E67B641246F264" 2117: "C8DE6D9A72E554D6C8D3194548780A0C438A0FCC509CA88A14AA1DEB" 2118: "C0F09E4B37A965D1545DB4AD361346F3189B0EA569C06D326C4E4797" 2119: "9E381C748293B7C0591BE0BE419E053E"), 2120: 2121: SessionKey = hexstr2bin("19D22C19612874EBF1F2581F8EFCFDC44C6FDA3B87B0A73823D7E962" 2122: "554295D4E48D3A336523ADBDDD0EC8FB0F02687109E97E01C17C93CC" 2123: "7216F9CD8A4AC39F0429857D8D1023066614BDFCBCB89F59A0FEB81C" 2124: "72E992AAD89095A84B6A5FADA152369AB1E350A03693BEF044DF3EDF" 2125: "0C34741F4696C30E9F675D09F58ACBEB"), 2126: UserPassHash = crypto:hash(sha, [Salt, crypto:hash(sha, [Username, <<$:>>, Password])]), 2127: Verifier = crypto:mod_pow(Generator, UserPassHash, Prime), 2128: ClientPublic = crypto:mod_pow(Generator, ClientPrivate, Prime), 2129: srp(ClientPrivate, Generator, Prime, Version, Verifier, ServerPublic, ServerPrivate, UserPassHash, Scrambler, SessionKey). 2130: 2131: 2132: srp6a_smaller_prime() -> 2133: Username = <<"alice">>, 2134: Password = <<"password123">>, 2135: Salt = <<"mystrongsalt">>, 2136: Prime = hexstr2bin("894B645E89E1535BBDAD5B8B290650530801B18EBFBF5E8FAB3C82872A3E9BB7"), 2137: Generator = <<7>>, 2138: Version = '6a', 2139: Scrambler = hexstr2bin("18DE4A002AD05EF464B19AE2B6929F9B1319C7AA"), 2140: Verifier = hexstr2bin("867401D5DE10964768184EAF246B322760C847604075FA66A4423907" 2141: "8428BCA5"), 2142: ClientPrivate = hexstr2bin("C49F832EE8D67ECF9E7F2785EB0622D8B3FE2344C00F96E1AEF4103C" 2143: "A44D51F9"), 2144: ServerPrivate = hexstr2bin("6C78CCEAAEC15E69068A87795B2A20ED7B45CFC5A254EBE2F17F144A" 2145: "4D99DB18"), 2146: ClientPublic = hexstr2bin("2452A57166BBBF690DB77539BAF9C57CD1ED99D5AA15ED925AD9B5C3" 2147: "64BBEDFF"), 2148: ServerPublic = hexstr2bin("2C0464DE84B91E4963A3546CAC0EFE55F31F49208C3F0AD7EE55F444" 2149: "8F38BA7F"), 2150: 2151: SessionKey = hexstr2bin("65581B2302580BD26F522A5A421CF969B9CCBCE4051196B034A2A9D22065D848"), 2152: UserPassHash = crypto:hash(sha, [Salt, crypto:hash(sha, [Username, <<$:>>, Password])]), 2153: Verifier = crypto:mod_pow(Generator, UserPassHash, Prime), 2154: ClientPublic = crypto:mod_pow(Generator, ClientPrivate, Prime), 2155: srp(ClientPrivate, Generator, Prime, Version, Verifier, ServerPublic, ServerPrivate, UserPassHash, Scrambler, SessionKey). 2156: 2157: srp6a() -> 2158: Username = <<"alice">>, 2159: Password = <<"password123">>, 2160: Salt = hexstr2bin("BEB25379D1A8581EB5A727673A2441EE"), 2161: Prime = hexstr2bin("EEAF0AB9ADB38DD69C33F80AFA8FC5E86072618775FF3C0B9EA2314C" 2162: "9C256576D674DF7496EA81D3383B4813D692C6E0E0D5D8E250B98BE4" 2163: "8E495C1D6089DAD15DC7D7B46154D6B6CE8EF4AD69B15D4982559B29" 2164: "7BCF1885C529F566660E57EC68EDBC3C05726CC02FD4CBF4976EAA9A" 2165: "FD5138FE8376435B9FC61D2FC0EB06E3"), 2166: Generator = <<2>>, 2167: Version = '6a', 2168: Scrambler = hexstr2bin("CE38B9593487DA98554ED47D70A7AE5F462EF019"), 2169: Verifier = hexstr2bin("7E273DE8696FFC4F4E337D05B4B375BEB0DDE1569E8FA00A9886D812" 2170: "9BADA1F1822223CA1A605B530E379BA4729FDC59F105B4787E5186F5" 2171: "C671085A1447B52A48CF1970B4FB6F8400BBF4CEBFBB168152E08AB5" 2172: "EA53D15C1AFF87B2B9DA6E04E058AD51CC72BFC9033B564E26480D78" 2173: "E955A5E29E7AB245DB2BE315E2099AFB"), 2174: ClientPrivate = hexstr2bin("60975527035CF2AD1989806F0407210BC81EDC04E2762A56AFD529DD" 2175: "DA2D4393"), 2176: ServerPrivate = hexstr2bin("E487CB59D31AC550471E81F00F6928E01DDA08E974A004F49E61F5D1" 2177: "05284D20"), 2178: ClientPublic = hexstr2bin("61D5E490F6F1B79547B0704C436F523DD0E560F0C64115BB72557EC4" 2179: "4352E8903211C04692272D8B2D1A5358A2CF1B6E0BFCF99F921530EC" 2180: "8E39356179EAE45E42BA92AEACED825171E1E8B9AF6D9C03E1327F44" 2181: "BE087EF06530E69F66615261EEF54073CA11CF5858F0EDFDFE15EFEA" 2182: "B349EF5D76988A3672FAC47B0769447B"), 2183: ServerPublic = hexstr2bin("BD0C61512C692C0CB6D041FA01BB152D4916A1E77AF46AE105393011" 2184: "BAF38964DC46A0670DD125B95A981652236F99D9B681CBF87837EC99" 2185: "6C6DA04453728610D0C6DDB58B318885D7D82C7F8DEB75CE7BD4FBAA" 2186: "37089E6F9C6059F388838E7A00030B331EB76840910440B1B27AAEAE" 2187: "EB4012B7D7665238A8E3FB004B117B58"), 2188: 2189: SessionKey = hexstr2bin("B0DC82BABCF30674AE450C0287745E7990A3381F63B387AAF271A10D" 2190: "233861E359B48220F7C4693C9AE12B0A6F67809F0876E2D013800D6C" 2191: "41BB59B6D5979B5C00A172B4A2A5903A0BDCAF8A709585EB2AFAFA8F" 2192: "3499B200210DCC1F10EB33943CD67FC88A2F39A4BE5BEC4EC0A3212D" 2193: "C346D7E474B29EDE8A469FFECA686E5A"), 2194: UserPassHash = crypto:hash(sha, [Salt, crypto:hash(sha, [Username, <<$:>>, Password])]), 2195: Verifier = crypto:mod_pow(Generator, UserPassHash, Prime), 2196: ClientPublic = crypto:mod_pow(Generator, ClientPrivate, Prime), 2197: srp(ClientPrivate, Generator, Prime, Version, Verifier, ServerPublic, ServerPrivate, UserPassHash, Scrambler, SessionKey). 2198: 2199: srp(ClientPrivate, Generator, Prime, Version, Verifier, ServerPublic, ServerPrivate, UserPassHash, Scrambler, SessionKey)-> 2200: {srp, ClientPrivate, 2201: {user, [Generator, Prime, Version]}, {user, [UserPassHash, Prime, Generator, Version, Scrambler]}, 2202: ServerPublic, ServerPrivate, {host, [Verifier, Generator, Prime, Version]}, 2203: {host, [Verifier, Prime, Version, Scrambler]}, 2204: SessionKey}. 2205: ecdh() -> 2206: %% http://csrc.nist.gov/groups/STM/cavp/ 2207: Curves = crypto:ec_curves(), 2208: TestCases = 2209: [{ecdh, hexstr2point("42ea6dd9969dd2a61fea1aac7f8e98edcc896c6e55857cc0", "dfbe5d7c61fac88b11811bde328e8a0d12bf01a9d204b523"), 2210: hexstr2bin("f17d3fea367b74d340851ca4270dcb24c271f445bed9d527"), 2211: secp192r1, 2212: hexstr2bin("803d8ab2e5b6e6fca715737c3a82f7ce3c783124f6d51cd0")}, 2213: {ecdh, hexstr2point("deb5712fa027ac8d2f22c455ccb73a91e17b6512b5e030e7", "7e2690a02cc9b28708431a29fb54b87b1f0c14e011ac2125"), 2214: hexstr2bin("56e853349d96fe4c442448dacb7cf92bb7a95dcf574a9bd5"), 2215: secp192r1, 2216: hexstr2bin("c208847568b98835d7312cef1f97f7aa298283152313c29d")}, 2217: {ecdh, hexstr2point("af33cd0629bc7e996320a3f40368f74de8704fa37b8fab69abaae280", "882092ccbba7930f419a8a4f9bb16978bbc3838729992559a6f2e2d7"), 2218: hexstr2bin("8346a60fc6f293ca5a0d2af68ba71d1dd389e5e40837942df3e43cbd"), 2219: secp224r1, 2220: hexstr2bin("7d96f9a3bd3c05cf5cc37feb8b9d5209d5c2597464dec3e9983743e8")}, 2221: {ecdh, hexstr2point("13bfcd4f8e9442393cab8fb46b9f0566c226b22b37076976f0617a46", "eeb2427529b288c63c2f8963c1e473df2fca6caa90d52e2f8db56dd4"), 2222: hexstr2bin("043cb216f4b72cdf7629d63720a54aee0c99eb32d74477dac0c2f73d"), 2223: secp224r1, 2224: hexstr2bin("ee93ce06b89ff72009e858c68eb708e7bc79ee0300f73bed69bbca09")}, 2225: {ecdh, hexstr2point("700c48f77f56584c5cc632ca65640db91b6bacce3a4df6b42ce7cc838833d287", "db71e509e3fd9b060ddb20ba5c51dcc5948d46fbf640dfe0441782cab85fa4ac"), 2226: hexstr2bin("7d7dc5f71eb29ddaf80d6214632eeae03d9058af1fb6d22ed80badb62bc1a534"), 2227: secp256r1, 2228: hexstr2bin("46fc62106420ff012e54a434fbdd2d25ccc5852060561e68040dd7778997bd7b")}, 2229: {ecdh, hexstr2point("809f04289c64348c01515eb03d5ce7ac1a8cb9498f5caa50197e58d43a86a7ae", "b29d84e811197f25eba8f5194092cb6ff440e26d4421011372461f579271cda3"), 2230: hexstr2bin("38f65d6dce47676044d58ce5139582d568f64bb16098d179dbab07741dd5caf5"), 2231: secp256r1, 2232: hexstr2bin("057d636096cb80b67a8c038c890e887d1adfa4195e9b3ce241c8a778c59cda67")}, 2233: {ecdh, hexstr2point("a7c76b970c3b5fe8b05d2838ae04ab47697b9eaf52e764592efda27fe7513272734466b400091adbf2d68c58e0c50066", "ac68f19f2e1cb879aed43a9969b91a0839c4c38a49749b661efedf243451915ed0905a32b060992b468c64766fc8437a"), 2234: hexstr2bin("3cc3122a68f0d95027ad38c067916ba0eb8c38894d22e1b15618b6818a661774ad463b205da88cf699ab4d43c9cf98a1"), 2235: secp384r1, 2236: hexstr2bin("5f9d29dc5e31a163060356213669c8ce132e22f57c9a04f40ba7fcead493b457e5621e766c40a2e3d4d6a04b25e533f1")}, 2237: {ecdh, hexstr2point("30f43fcf2b6b00de53f624f1543090681839717d53c7c955d1d69efaf0349b7363acb447240101cbb3af6641ce4b88e0", "25e46c0c54f0162a77efcc27b6ea792002ae2ba82714299c860857a68153ab62e525ec0530d81b5aa15897981e858757"), 2238: hexstr2bin("92860c21bde06165f8e900c687f8ef0a05d14f290b3f07d8b3a8cc6404366e5d5119cd6d03fb12dc58e89f13df9cd783"), 2239: secp384r1, 2240: hexstr2bin("a23742a2c267d7425fda94b93f93bbcc24791ac51cd8fd501a238d40812f4cbfc59aac9520d758cf789c76300c69d2ff")}, 2241: {ecdh, hexstr2point("00685a48e86c79f0f0875f7bc18d25eb5fc8c0b07e5da4f4370f3a9490340854334b1e1b87fa395464c60626124a4e70d0f785601d37c09870ebf176666877a2046d", "01ba52c56fc8776d9e8f5db4f0cc27636d0b741bbe05400697942e80b739884a83bde99e0f6716939e632bc8986fa18dccd443a348b6c3e522497955a4f3c302f676"), 2242: hexstr2bin("017eecc07ab4b329068fba65e56a1f8890aa935e57134ae0ffcce802735151f4eac6564f6ee9974c5e6887a1fefee5743ae2241bfeb95d5ce31ddcb6f9edb4d6fc47"), 2243: secp521r1, 2244: hexstr2bin("005fc70477c3e63bc3954bd0df3ea0d1f41ee21746ed95fc5e1fdf90930d5e136672d72cc770742d1711c3c3a4c334a0ad9759436a4d3c5bf6e74b9578fac148c831")}, 2245: {ecdh, hexstr2point("01df277c152108349bc34d539ee0cf06b24f5d3500677b4445453ccc21409453aafb8a72a0be9ebe54d12270aa51b3ab7f316aa5e74a951c5e53f74cd95fc29aee7a", "013d52f33a9f3c14384d1587fa8abe7aed74bc33749ad9c570b471776422c7d4505d9b0a96b3bfac041e4c6a6990ae7f700e5b4a6640229112deafa0cd8bb0d089b0"), 2246: hexstr2bin("00816f19c1fb10ef94d4a1d81c156ec3d1de08b66761f03f06ee4bb9dcebbbfe1eaa1ed49a6a990838d8ed318c14d74cc872f95d05d07ad50f621ceb620cd905cfb8"), 2247: secp521r1, 2248: hexstr2bin("000b3920ac830ade812c8f96805da2236e002acbbf13596a9ab254d44d0e91b6255ebf1229f366fb5a05c5884ef46032c26d42189273ca4efa4c3db6bd12a6853759")}, 2249: 2250: %% RFC-6954, Appendix A 2251: {ecdh, hexstr2point("A9C21A569759DA95E0387041184261440327AFE33141CA04B82DC92E", 2252: "98A0F75FBBF61D8E58AE5511B2BCDBE8E549B31E37069A2825F590C1"), 2253: hexstr2bin("6060552303899E2140715816C45B57D9B42204FB6A5BF5BEAC10DB00"), 2254: brainpoolP224r1, 2255: hexstr2bin("1A4BFE705445120C8E3E026699054104510D119757B74D5FE2462C66")}, 2256: {ecdh, hexstr2point("034A56C550FF88056144E6DD56070F54B0135976B5BF77827313F36B", 2257: "75165AD99347DC86CAAB1CBB579E198EAF88DC35F927B358AA683681"), 2258: hexstr2bin("39F155483CEE191FBECFE9C81D8AB1A03CDA6790E7184ACE44BCA161"), 2259: brainpoolP224r1, 2260: hexstr2bin("1A4BFE705445120C8E3E026699054104510D119757B74D5FE2462C66")}, 2261: {ecdh, hexstr2point("44106E913F92BC02A1705D9953A8414DB95E1AAA49E81D9E85F929A8E3100BE5", 2262: "8AB4846F11CACCB73CE49CBDD120F5A900A69FD32C272223F789EF10EB089BDC"), 2263: hexstr2bin("55E40BC41E37E3E2AD25C3C6654511FFA8474A91A0032087593852D3E7D76BD3"), 2264: brainpoolP256r1, 2265: hexstr2bin("89AFC39D41D3B327814B80940B042590F96556EC91E6AE7939BCE31F3A18BF2B")}, 2266: {ecdh, hexstr2point("8D2D688C6CF93E1160AD04CC4429117DC2C41825E1E9FCA0ADDD34E6F1B39F7B", 2267: "990C57520812BE512641E47034832106BC7D3E8DD0E4C7F1136D7006547CEC6A"), 2268: hexstr2bin("81DB1EE100150FF2EA338D708271BE38300CB54241D79950F77B063039804F1D"), 2269: brainpoolP256r1, 2270: hexstr2bin("89AFC39D41D3B327814B80940B042590F96556EC91E6AE7939BCE31F3A18BF2B")}, 2271: {ecdh, hexstr2point("68B665DD91C195800650CDD363C625F4E742E8134667B767B1B476793588F885AB698C852D4A6E77A252D6380FCAF068", 2272: "55BC91A39C9EC01DEE36017B7D673A931236D2F1F5C83942D049E3FA20607493E0D038FF2FD30C2AB67D15C85F7FAA59"), 2273: hexstr2bin("032640BC6003C59260F7250C3DB58CE647F98E1260ACCE4ACDA3DD869F74E01F8BA5E0324309DB6A9831497ABAC96670"), 2274: brainpoolP384r1, 2275: hexstr2bin("0BD9D3A7EA0B3D519D09D8E48D0785FB744A6B355E6304BC51C229FBBCE239BBADF6403715C35D4FB2A5444F575D4F42")}, 2276: {ecdh, hexstr2point("4D44326F269A597A5B58BBA565DA5556ED7FD9A8A9EB76C25F46DB69D19DC8CE6AD18E404B15738B2086DF37E71D1EB4", 2277: "62D692136DE56CBE93BF5FA3188EF58BC8A3A0EC6C1E151A21038A42E9185329B5B275903D192F8D4E1F32FE9CC78C48"), 2278: hexstr2bin("1E20F5E048A5886F1F157C74E91BDE2B98C8B52D58E5003D57053FC4B0BD65D6F15EB5D1EE1610DF870795143627D042"), 2279: brainpoolP384r1, 2280: hexstr2bin("0BD9D3A7EA0B3D519D09D8E48D0785FB744A6B355E6304BC51C229FBBCE239BBADF6403715C35D4FB2A5444F575D4F42")}, 2281: {ecdh, hexstr2point("0A420517E406AAC0ACDCE90FCD71487718D3B953EFD7FBEC5F7F27E28C6149999397E91E029E06457DB2D3E640668B392C2A7E737A7F0BF04436D11640FD09FD", 2282: "72E6882E8DB28AAD36237CD25D580DB23783961C8DC52DFA2EC138AD472A0FCEF3887CF62B623B2A87DE5C588301EA3E5FC269B373B60724F5E82A6AD147FDE7"), 2283: hexstr2bin("230E18E1BCC88A362FA54E4EA3902009292F7F8033624FD471B5D8ACE49D12CFABBC19963DAB8E2F1EBA00BFFB29E4D72D13F2224562F405CB80503666B25429"), 2284: brainpoolP512r1, 2285: hexstr2bin("A7927098655F1F9976FA50A9D566865DC530331846381C87256BAF3226244B76D36403C024D7BBF0AA0803EAFF405D3D24F11A9B5C0BEF679FE1454B21C4CD1F")}, 2286: {ecdh, hexstr2point("9D45F66DE5D67E2E6DB6E93A59CE0BB48106097FF78A081DE781CDB31FCE8CCBAAEA8DD4320C4119F1E9CD437A2EAB3731FA9668AB268D871DEDA55A5473199F", 2287: "2FDC313095BCDD5FB3A91636F07A959C8E86B5636A1E930E8396049CB481961D365CC11453A06C719835475B12CB52FC3C383BCE35E27EF194512B71876285FA"), 2288: hexstr2bin("16302FF0DBBB5A8D733DAB7141C1B45ACBC8715939677F6A56850A38BD87BD59B09E80279609FF333EB9D4C061231FB26F92EEB04982A5F1D1764CAD57665422"), 2289: brainpoolP512r1, 2290: hexstr2bin("A7927098655F1F9976FA50A9D566865DC530331846381C87256BAF3226244B76D36403C024D7BBF0AA0803EAFF405D3D24F11A9B5C0BEF679FE1454B21C4CD1F")}], 2291: lists:filter(fun ({_Type, _Pub, _Priv, Curve, _SharedSecret}) -> 2292: lists:member(Curve, Curves) 2293: end, 2294: TestCases). 2295: 2296: dh() -> 2297: {dh, 0087761979513264537414556992123116644042638206717762626089877284926656954974893442000747478454809111207351620687968672207938731607963470779396984752680274820156266685080223616226905101126463253150237669547023934604953898814222890239130021414026118792251620881355456432549881723310342870016961804255746630219, 2}. 2298: 2299: rsa_oaep() -> 2300: %% ftp://ftp.rsa.com/pub/rsalabs/tmp/pkcs1v15crypt-vectors.txt 2301: Public = [hexstr2bin("010001"), 2302: hexstr2bin("a8b3b284af8eb50b387034a860f146c4919f318763cd6c5598c8ae4811a1e0abc4c7e0b082d693a5e7fced675cf4668512772c0cbc64a742c6c630f533c8cc72f62ae833c40bf25842e984bb78bdbf97c0107d55bdb662f5c4e0fab9845cb5148ef7392dd3aaff93ae1e6b667bb3d4247616d4f5ba10d4cfd226de88d39f16fb")], 2303: Private = Public ++ [hexstr2bin("53339cfdb79fc8466a655c7316aca85c55fd8f6dd898fdaf119517ef4f52e8fd8e258df93fee180fa0e4ab29693cd83b152a553d4ac4d1812b8b9fa5af0e7f55fe7304df41570926f3311f15c4d65a732c483116ee3d3d2d0af3549ad9bf7cbfb78ad884f84d5beb04724dc7369b31def37d0cf539e9cfcdd3de653729ead5d1"), 2304: hexstr2bin("d32737e7267ffe1341b2d5c0d150a81b586fb3132bed2f8d5262864a9cb9f30af38be448598d413a172efb802c21acf1c11c520c2f26a471dcad212eac7ca39d"), 2305: hexstr2bin("cc8853d1d54da630fac004f471f281c7b8982d8224a490edbeb33d3e3d5cc93c4765703d1dd791642f1f116a0dd852be2419b2af72bfe9a030e860b0288b5d77"), 2306: hexstr2bin("0e12bf1718e9cef5599ba1c3882fe8046a90874eefce8f2ccc20e4f2741fb0a33a3848aec9c9305fbecbd2d76819967d4671acc6431e4037968db37878e695c1"), 2307: hexstr2bin("95297b0f95a2fa67d00707d609dfd4fc05c89dafc2ef6d6ea55bec771ea333734d9251e79082ecda866efef13c459e1a631386b7e354c899f5f112ca85d71583"), 2308: hexstr2bin("4f456c502493bdc0ed2ab756a3a6ed4d67352a697d4216e93212b127a63d5411ce6fa98d5dbefd73263e3728142743818166ed7dd63687dd2a8ca1d2f4fbd8e1")], 2309: %%Msg = hexstr2bin("6628194e12073db03ba94cda9ef9532397d50dba79b987004afefe34"), 2310: Msg = hexstr2bin("750c4047f547e8e41411856523298ac9bae245efaf1397fbe56f9dd5"), 2311: {rsa, Public, Private, Msg, rsa_pkcs1_oaep_padding}. 2312: 2313: ecc() -> 2314: %% http://point-at-infinity.org/ecc/nisttv 2315: %% 2316: %% Test vectors for the NIST elliptic curves P192, P224, P256, P384, P521, 2317: %% B163, B233, B283, B409, B571, K163, K233, K283, K409 and K571. For more 2318: %% information about the curves see 2319: %% http://csrc.nist.gov/encryption/dss/ecdsa/NISTReCur.pdf 2320: %% 2321: Curves = crypto:ec_curves(), 2322: TestCases = 2323: [{ecdh,secp192r1,1, 2324: hexstr2point("188DA80EB03090F67CBF20EB43A18800F4FF0AFD82FF1012", 2325: "07192B95FFC8DA78631011ED6B24CDD573F977A11E794811")}, 2326: {ecdh,secp192r1,2, 2327: hexstr2point("DAFEBF5828783F2AD35534631588A3F629A70FB16982A888", 2328: "DD6BDA0D993DA0FA46B27BBC141B868F59331AFA5C7E93AB")}, 2329: {ecdh,secp192r1,3, 2330: hexstr2point("76E32A2557599E6EDCD283201FB2B9AADFD0D359CBB263DA", 2331: "782C37E372BA4520AA62E0FED121D49EF3B543660CFD05FD")}, 2332: {ecdh,secp192r1,4, 2333: hexstr2point("35433907297CC378B0015703374729D7A4FE46647084E4BA", 2334: "A2649984F2135C301EA3ACB0776CD4F125389B311DB3BE32")}], 2335: lists:filter(fun ({_Type, Curve, _Priv, _Pub}) -> 2336: lists:member(Curve, Curves) 2337: end, 2338: TestCases). 2339: 2340: no_padding() -> 2341: Public = [_, Mod] = rsa_public(), 2342: Private = rsa_private(), 2343: MsgLen = erlang:byte_size(int_to_bin(Mod)), 2344: Msg = list_to_binary(lists:duplicate(MsgLen, $X)), 2345: {rsa, Public, Private, Msg, rsa_no_padding}. 2346: 2347: int_to_bin(X) when X < 0 -> int_to_bin_neg(X, []); 2348: int_to_bin(X) -> int_to_bin_pos(X, []). 2349: 2350: int_to_bin_pos(0,Ds=[_|_]) -> 2351: list_to_binary(Ds); 2352: int_to_bin_pos(X,Ds) -> 2353: int_to_bin_pos(X bsr 8, [(X band 255)|Ds]). 2354: 2355: int_to_bin_neg(-1, Ds=[MSB|_]) when MSB >= 16#80 -> 2356: list_to_binary(Ds); 2357: int_to_bin_neg(X,Ds) -> 2358: int_to_bin_neg(X bsr 8, [(X band 255)|Ds]).