оÊÖÒÕ | »ùÓÚQG¹Î¹ÎÀÖ´¦Öóͷ£Æ÷µÄ¹úÃÜËã·¨¼ÓËÙÖ¸ÁîʹÓÃ˵Ã÷

Ðû²¼ÈÕÆÚ£º

2020-08-21

ȪԴ£º

1.¸ÅÊö

ÐÅÏ¢ÊÖÒյĿìËÙÉú³¤ÎªÈËÀàÉç»á´øÀ´ÁËÉî¿ÌµÄÀå¸ï ¡£Ëæ×ÅÅÌËã»úÊÖÒյĿìËÙÉú³¤ £¬ÎÒ¹úÔÚµç×ÓÒøÐС¢µç×ÓÉÌÎñºÍµç×ÓÕþÎñµÈ·½ÃæµÄÆÕ±éÓ¦Óà £¬Ê¹ÅÌËã»úÇå¾²ÎÊÌâÒѾ­ÉîÈëµ½¹ú¼ÒµÄÕþÖΡ¢¾­¼Ã¡¢ÎÄ»¯½¨ÉèµÈ¸÷¸öÁìÓò £¬±é²¼ÏÖ´úÐÅÏ¢»¯Éç»áµÄÊÂÇéºÍÉúÑĵÄÿ¸ö²ãÃæ ¡£QG¹Î¹ÎÀÖÌìÏ´ÓûÓÐÏñ½ñÌìÕâÑù¹Øע֪ʶ²úȨ¡¢Ð¡ÎÒ˽¼ÒÉí·ÝÐÅÏ¢ÒÔ¼°ÆäËûÃô¸ÐÐÅÏ¢µÄ± £»¤ ¡£


¹úÃÜËã·¨ÊÇÖ¸Óɹú¼ÒÃÜÂëÖÎÀí¾ÖÖƶ©µÄһϵÁÐÃÜÂë±ê×¼ £¬ÆäÓ¦ÓÃÁìÓòÊ®·ÖÆÕ±é £¬¿ÉÓÃÓÚ¶Ô¾ßÓÐÃô¸ÐÐÔµÄÄÚ²¿ÐÅÏ¢¡¢ÐÐÕþÊÂÎñÐÅÏ¢¡¢¾­¼ÃÐÅÏ¢µÈ¾ÙÐмÓÃܱ £»¤ ¡£ºÃ±È£ºÓÃÓÚÆóҵÎûÖÎÀí¡¢ÆóÒµÄÚ²¿µÄÖÖÖÖÃô¸ÐÐÅÏ¢µÄ´«Êä¼ÓÃÜ¡¢´æ´¢¼ÓÃÜ £¬±ÜÃâ²»·¨µÚÈý·½»ñÊØÐÅÏ¢ÄÚÈÝ £»Ò²¿ÉÓÃÓÚÖÖÖÖÇå¾²ÈÏÖ¤¡¢ÍøÉÏÒøÐС¢Êý×ÖÊðÃûµÈ ¡£


ÆäÖÐ £¬SM3ÃÜÂëÔÓ´ÕËã·¨ÊÇΪ֪×ãµç×ÓÈÏ֤ЧÀÍϵͳµÈÓ¦ÓÃÐèÇó £¬¹ú¼ÒÃÜÂëÖÎÀí¾ÖÓÚ2010Äê12ÔÂ17ÈÕÐû²¼ ¡£¸Ã±ê×¼ÊÊÓÃÓÚÉÌÓÃÃÜÂëÓ¦ÓÃÖеÄÊý×ÖÊðÃûºÍÑéÖ¤¡¢ÐÂÎÅÈÏÖ¤ÂëµÄÌìÉúÓëÑéÖ¤ÒÔ¼°Ëæ»úÊýµÄÌìÉú £¬¿ÉÖª×ã¶àÖÖÃÜÂëÓ¦ÓõÄÇå¾²ÐèÇó ¡£SM4·Ö×éÃÜÂëËã·¨ £¬¹ú¼ÒÃÜÂëÖÎÀí¾ÖÓÚ2012Äê3ÔÂ21ÈÕÐû²¼ £¬¸Ã±ê×¼ÊÊÓÃÓÚÃÜÂëÓ¦ÓÃÖÐʹÓ÷Ö×éÃÜÂëµÄÐèÇó ¡£


ÏÖÔÚ³£¼ûµÄÖ§³Ö¹úÃÜËã·¨µÄ×°±¸ºÃ±ÈоƬÀàµÄTPM/TCM £¬ÍùÍùÊÜÏÞÓÚÆ䱾Ǯ¶øÐÔÄܺܵÍ £»ÐÔÄܽϸߵļÓÃÜ¿¨ÍùÍùÐèÒª¸ßÐÔÄܵÄÅÌËã»úÀ´ÅäºÏ £¬Õâ¾Í¸øÓû§´øÀ´Á˲»Ð¡µÄ±¾Ç®Ñ¹Á¦ ¡£¶øÓë´Ëͬʱ £¬¾­Óɼ¸´ú²úÆ·µÄÉú³¤ £¬QG¹Î¹ÎÀÖCPUµÄÐÔÄÜÓÐÁË´ó·ùÌáÉý ¡£ÔÚ×¢ÖØЧÄÜ £¬Ç¿µ÷ÐԼ۱ȵĽñÌì £¬Óû§×ÔȻϣÍûÄܹ»³ä·ÖʹÓÃCPUµÄÅÌËãÄÜÁ¦ £¬Óɴ˱㱬·¢ÁËʹÓÃCPUÖ¸ÁîÀ´ÊµÏÖ¹úÃÜËã·¨µÄÏë·¨ ¡£Õâ¼´ÊÇÉè¼Æ»ùÓÚQG¹Î¹ÎÀÖCPUµÄ¹úÃÜËã·¨¼ÓËÙÖ¸ÁîGMI£¨ÒÔϼò³ÆGMI£©µÄ³õÖ¾ ¡£


GMIÊÇQG¹Î¹ÎÀÖÒÀ¾Ý¹úÃÜËã·¨±ê×¼¶ø×ÔÖ÷Ñз¢Éè¼ÆʵÏÖµÄÒ»×éÓ²¼þ¼ÓËÙÖ¸Á ¡£ÏÖÔÚÒѾ­ÊµÏÖÁËÁ½Ìõ¹úÃÜËã·¨Ö¸ÁSM3ºÍSM4 ¡£ÆäÖÐ £¬SM4Ö§³Ö³£¼ûµÄECB¡¢CBC¡¢CTR¡¢OFB¡¢CFBÎåÖÖģʽ ¡£Í¨¹ý¶ÔGMIµÄʹÓà £¬ÎÒÃDz»µ«ÄÜÈÃÃÜÂëѧËã·¨Ô½·¢Çå¾²Ò×Óà £¬²¢ÇÒ»¹ÄÜ»ñµÃ±ÈÈí¼þʵÏָߵöàµÄÐÔÄÜ ¡£


SM2Ö¸Áî £¬¼´½«ÔÚÏÂÒ»´úQG¹Î¹ÎÀÖGMIÀïÌí¼Ó £¬½ìʱ £¬GMI³ýÁËÖ§³ÖÉÏÃæÌáµ½µÄHASHËã·¨SM3 £¬¶Ô³ÆËã·¨SM4 £¬»¹½«Ö§³Ö·Ç¶Ô³ÆËã·¨SM2µÄ²¿·Ö»òËùÓй¦Ð§ £¬°üÀ¨Ö§³ÖSM2ÊðÃûºÍÑéÖ¤ £»SM2¼ÓÃÜÏ¢ÕùÃÜ £»SM2ÃÜÔ¿ÌìÉúºÍÃÜÔ¿½»Á÷µÈ¹¦Ð§ ¡£¾´ÇëÆÚ´ý ¡£


ͼ±í 1. GMIÖ§³ÖµÄ¹úÃÜËã·¨Ö¸Áî

Ö¸Áî

Opcode

˵Ã÷

CCS_HASH

0xF3 0x0F 0xA6 0xE8

SM3Ö¸Áî

CCS_ENCRYPT

0xF3 0x0F 0xA7 0xF0

SM4Ö¸Áî

±¾ÎĺóÃæµÄÕ½ڻá´ÓGMI´ø¸ø¿Í»§µÄ¼ÛÖµ £¬Ó¦ÓÃÄ£×Ó £¬Ö¸ÁîÏÈÈݺÍGMIÈí¼þ½â¾ö¼Æ»®µÈ½Ç¶È¸ø³öGMIÖ¸ÁîÔÚQG¹Î¹ÎÀÖÖ÷Á÷CPUÉϵÄÐÔÄÜÆÀ²âÒªÁìºÍЧ¹û £¬ÒÔ¼°GMIÆÕ±éµÄʹÓó¡¾° ¡£²¢ÎªÀû±ã¿Í»§Ê¹ÓÃGMI £¬±¾ÎÄ»¹¶ÔQG¹Î¹ÎÀÖGMIÅäÌ×Èí¼þ½â¾ö¼Æ»®¸ø³öÁ˽ÏΪÏêϸµÄÏÈÈÝ£¨¸ü¶àÊÊÅäÊÂÇéÒ²ÇëËæʱÁªÏµQG¹Î¹ÎÀÖ£© ¡£


2.GMI´ø¸ø¿Í»§µÄ¼ÛÖµ


2.1 Ò×ÓÃÐÔ

¹Å°åµÄ¹úÃÜËã·¨µÄʹÓ÷½·¨ÖÐ £¬½ÏÁ¿³£¼ûµÄ¾ÍÊÇͨ¹ýÈí¼þ±à³ÌµÄ·½·¨À´ÊµÏÖÏìÓ¦µÄÃÜÂëËã·¨ £¬Õâͨ³£¶¼ÐèÒª¾ÙÐдó×Ú¡¢ÖØ´óµÄ±à³Ì ¡£ÒÔOpenSSLΪÀý £¬ SM3¡¢SM4µÄ´úÂëÁ¿»òÐíÔÚ200~300ÐÐ×óÓÒ £¬¿ÉÊÇÔÚ½«ÕâЩÃÜÂëËã·¨¾ÙÐÐÓ²¼þÖ¸Áºó £¬Ô­±¾ÐèҪʹÓÃÊý°ÙÐÐÖØ´ó±àÂë²Å¿ÉÒÔʵÏÖµÄËã·¨ÏÖÔÚÖ»ÐèÒª¼òÆÓŲÓÃÒ»ÌõÓ²¼þÖ¸Áî¼´¿ÉÍê³ÉÏìÓ¦µÄ²Ù×÷ ¡£ÕâºÁÎÞÒÉÎÊ´ó´ó¼ò»¯Á˲Ù×÷µÄÖØƯºó £¬ÎªÓû§´øÀ´Á˼«´óµÄ±ãµ±ÐÔ ¡£


2.2 Çå¾²ÐÔ

ÖÚËùÖÜÖª £¬ÎÞÂÛÊÇÔÚÔËÐÐ֮ǰ £¬ÕÕ¾ÉÔÚÔËÐеÄÀú³ÌÖÐ, Èí¼þ×î³£Óöµ½µÄ¹¥»÷¾ÍÊDZ»²»·¨¸Ä¶¯ ¡£Ê¹ÓÃÈí¼þ±à³ÌʵÏÖµÄÃÜÂëË㷨ҲͬÑù»áÊܵ½ÕâÀàÍþв ¡£È»¶øÓ²¼þ²»±£´æ±»¸Ä¶¯µÄΣº¦, Òò´ËÔÚ½«ÃÜÂëËã·¨Ó²¼þ¹Ì»¯ºó, Ò²¾ÍÏû³ýÁËÃÜÂëËã·¨±»²»·¨¸Ä¶¯µÄΣº¦ £¬Áô¸ø¹¥»÷ÕߵĹ¥»÷ÃæÒ²ÏìÓ¦¼õС ¡£²¢ÇÒÔÚÃÜÂëË㷨ʵÏÖÓ²¼þ»¯ºó £¬²»Ö¹ÓÃÓÚʵÏÖËã·¨µÄ´úÂëÁ¿»á±äÉÙ £¬ÏìÓ¦µÄŲÓá¢Ê¹ÓÃÃÜÂëËã·¨µÄ´úÂëÁ¿Ò²»áËæ×ÅïÔÌ­ £¬ÕâÒ²¾ÍÒâζ×ÅÔÚ³ÌÐòÖÐÒýÈëbugµÄ¼¸ÂÊÒ²»á´ó´ó½µµÍ ¡£ÕâЩÎÞÒɶ¼´ó´óÔöÇ¿ÁËÓû§³ÌÐòµÄÇå¾²ÐÔ ¡£


2.3 ¸ßЧÐÔ

ͨ¹ý½«ÃÜÂëËã·¨Ó²¼þ»¯ºó £¬Ê¹µÃÃÜÂëËã·¨»ñµÃ¼«´óµÄÐÔÄÜÌáÉý £¬ÕâÕýÊÇÎÒÃÇÏ£Íû³ä·ÖʹÓÃCPUµÄÅÌËãÄÜÁ¦µÄ³õÖ¾ ¡£ÎÒÃÇͨ¹ý½«GMIÒÔengine·½·¨¼¯³Éµ½OpenSSLºó £¬½èÖúÓÚOpenSSLµÄspeed benchmarkÏÂÁî £¬²âÊÔÁËÈí¡¢Ó²¼þÁ½ÖÖ·½·¨ÏµĹúÃÜËã·¨µÄÐÔÄÜ£¨µ¥Ị̈߳© £¬¶ÔºÃ±ÈÏ£¨KX-6000/KX-5000/ZX-C+»®·ÖÊÇQG¹Î¹ÎÀÖCPUÈý´ú²úÆ·µÄ´úºÅ£©£º


ͼ±í 2. SM3ÐÔÄܽÏÁ¿

»ùÓÚQG¹Î¹ÎÀÖ´¦Öóͷ£Æ÷µÄ¹úÃÜËã·¨¼ÓËÙÖ¸Áî  Ê¹ÓÃ˵Ã÷

»ùÓÚQG¹Î¹ÎÀÖ´¦Öóͷ£Æ÷µÄ¹úÃÜËã·¨¼ÓËÙÖ¸Áî  Ê¹ÓÃ˵Ã÷

´ÓÉÏÃæµÄÆÀ²âЧ¹û¿ÉÒÔ¿´µ½ £¬Ëæ×ÅÕªÒªÊý¾ÝÁ¿µÄÔö´ó £¬ÔÚÖ÷ƵÏ൱µÄÇéÐÎÏ £¬GMIµÄÐÔÄÜÓÅÊÆÏà¹ØÓÚi7 CPUÓú·¢Ã÷ÏÔ £¬ÔÚ´óÊý¾ÝÁ¿ÏÂÐÔÄÜ¿ÉÒÔÊÇIntel i7µÄ2±¶ÒÔÉÏ £¬Òò´ËʹÓÃGMIÀ´ÊµÏÖSM3¼ÓÃܲúÆ·¿ÉÒÔʵÏÖÔÚ¸ü¶ÌµÄʱ¼äÄÚ¶Ô¸ü´óÊý¾ÝÁ¿µÄÕªÒªÅÌËã ¡£


ͼ±í 3. SM4-ECBÐÔÄܽÏÁ¿

»ùÓÚQG¹Î¹ÎÀÖ´¦Öóͷ£Æ÷µÄ¹úÃÜËã·¨¼ÓËÙÖ¸Áî  Ê¹ÓÃ˵Ã÷

»ùÓÚQG¹Î¹ÎÀÖ´¦Öóͷ£Æ÷µÄ¹úÃÜËã·¨¼ÓËÙÖ¸Áî  Ê¹ÓÃ˵Ã÷


ͼ±í 4. SM4-CBCÐÔÄܽÏÁ¿

»ùÓÚQG¹Î¹ÎÀÖ´¦Öóͷ£Æ÷µÄ¹úÃÜËã·¨¼ÓËÙÖ¸Áî  Ê¹ÓÃ˵Ã÷

»ùÓÚQG¹Î¹ÎÀÖ´¦Öóͷ£Æ÷µÄ¹úÃÜËã·¨¼ÓËÙÖ¸Áî  Ê¹ÓÃ˵Ã÷


ͼ±í 5. SM4-CTRÐÔÄܽÏÁ¿

»ùÓÚQG¹Î¹ÎÀÖ´¦Öóͷ£Æ÷µÄ¹úÃÜËã·¨¼ÓËÙÖ¸Áî  Ê¹ÓÃ˵Ã÷

»ùÓÚQG¹Î¹ÎÀÖ´¦Öóͷ£Æ÷µÄ¹úÃÜËã·¨¼ÓËÙÖ¸Áî  Ê¹ÓÃ˵Ã÷


ͼ±í 6. SM4-OFBÐÔÄܽÏÁ¿

»ùÓÚQG¹Î¹ÎÀÖ´¦Öóͷ£Æ÷µÄ¹úÃÜËã·¨¼ÓËÙÖ¸Áî  Ê¹ÓÃ˵Ã÷

»ùÓÚQG¹Î¹ÎÀÖ´¦Öóͷ£Æ÷µÄ¹úÃÜËã·¨¼ÓËÙÖ¸Áî  Ê¹ÓÃ˵Ã÷


ͼ±í 7. SM4-CFBÐÔÄܽÏÁ¿

»ùÓÚQG¹Î¹ÎÀÖ´¦Öóͷ£Æ÷µÄ¹úÃÜËã·¨¼ÓËÙÖ¸Áî  Ê¹ÓÃ˵Ã÷

»ùÓÚQG¹Î¹ÎÀÖ´¦Öóͷ£Æ÷µÄ¹úÃÜËã·¨¼ÓËÙÖ¸Áî  Ê¹ÓÃ˵Ã÷


SM4·Ö×éÃÜÂëËã·¨ÍùÍùÓÃÔÚ´óÊý¾Ý¼ÓÃܵij¡¾°Ï £¬Òò´ËÔÚÏÖʵӦÓÃÖÐÆäÊý¾ÝÁ¿ÍùÍùºÜÊÇ´ó ¡£Í¨¹ýÉÏÃæµÄÐÔÄÜÆÊÎö±ÈÕÕ¿ÉÒÔ¿´µ½ £¬ÔÚÖ÷ƵÏ൱µÄÇéÐÎÏ £¬Ê¹ÓÃGMIºóµÄ¼ÓÃÜÐÔÄܾùÓÅÓÚi7ÐÔÄÜ ¡£ÌØÊâÊÇÔÚ´¦Öóͷ£´óÊý¾Ý¿éʱ £¬ÌáÉýÓÈÆäÏÔ×Å ¡£?


3.GMIµÄÓ¦ÓÃÄ£×Ó


3.1 SM3µÄÓ¦ÓÃÄ£×Ó

ÍêÕûÐÔÊÇÐÅÏ¢Çå¾²ÖÐÈý´ó»ù±¾ÒªËØCIA(confidentialityÉñÃØÐÔ £¬integrityÍêÕûÐÔ £¬availability¿ÉÓÃÐÔ)Ö®Ò» ¡£ÎªÁËÈ·±£ËùʹÓõÄÎļþ»òÕßÈí¼þÊÇûÓб»ºÚ¿Í¸Ä¶¯¹ýµÄ £¬ÍùÍùÐèҪУÑéÎļþµÄÍêÕûÐÔ ¡£ÏÖÔÚ½ÏÁ¿³£¼ûµÄÎļþУÑéËã·¨ÓÐÆæżУÑéºÍCRCУÑé £¬¿ÉÊÇÕâÁ½ÖÖУÑ鲢ûÓп¹Êý¾Ý¸Ä¶¯µÄÄÜÁ¦ ¡£È»¶ø £¬ÓÉÓÚ¹þÏ£Ëã·¨µÄÌصã £¬SM3Ôò¿ÉÒÔУÑé³öí§Òⳤ¶ÈµÄ¸Ä¶¯ ¡£Òò´Ë £¬Óû§Ö»ÐèҪŲÓÃGMIµÄSM3Ö¸ÁîÅÌËãËùÓõ½µÄÎļþ/Èí¼þµÄÕªÒªÖµ £¬ÓëÎļþ/Èí¼þ×Ô´øµÄУÑéÖµ¾ÙÐнÏÁ¿ £¬¾Í¿ÉÒÔÄ¥Á·³öÎļþ/Èí¼þÊÇ·ñ±»¸Ä¶¯¹ý £¬°ü¹ÜÁËËùÓÃÎļþ/Èí¼þµÄÍêÕûÐÔ ¡£


±ðµÄ £¬ÓÉÓÚÔÚÅÌËãÐÅϢժҪʱ, Óû§ËùÌåÌùµÄÖ÷ÒªÊÇÐÂÎŵÄÍêÕûÐÔ £¬¶ø²»ÊÇÉñÃØÐÔ £¬Òò´Ë £¬ÔÚʹÓÃÐÔÄܽϵ͵ÄÇ徲оƬ»òÕß¼ÓÃÜ¿¨Ê± £¬¿ÉÒÔ½«ÅÌËãÕªÒªÖµµÄÊÂÇé½»¸øGMIµÄSM3Ö¸ÁîÀ´Íê³É £¬ÒÔ»ñÈ¡¸ü¸ßµÄϵͳÐÔÄÜ ¡£


3.2 SM4µÄÓ¦ÓÃÄ£×Ó

¸úÆäËûµÄ¶Ô³Æ¼Ó½âÃÜËã·¨Ò»Ñù £¬SM4ͬÑù¿ÉÒÔÓÃÔÚ¾²Ì¬Êý¾Ý¼ÓÃÜ¡¢´«ÊäÊý¾Ý¼ÓÃÜÒÔ¼°Ó¦ÓòãµÄÊý¾Ý¼ÓÃÜ ¡£


1)¾²Ì¬Êý¾Ý¼ÓÃÜ

¾²Ì¬Êý¾Ý¼ÓÃÜÒ»¸öµä·¶Ó¦ÓÃÊÇÈ«´ÅÅ̼ÓÃÜ ¡£Ëæ×ÅÐÅÏ¢µÄµç×Ó»¯ £¬ÉúÑÄÔÚÅÌËã»úÉè±¹ØÁ¬ÄСÎÒ˽¼ÒÐÅÏ¢ £¬ÉÌÒµÐÅÏ¢µÈÃô¸ÐÊý¾ÝµÄÇå¾²ÐÔÔ½À´Ô½Êܵ½ÈËÃǵÄÖØÊÓ ¡£¹ØÓÚСÎÒ˽¼Ò¿Í»§À´Ëµ £¬Ð¡ÎÒ˽¼ÒµÄÃÜÂë £¬ÕÕƬ £¬ÊÓƵµÈÒ»Ñùƽ³£¶¼ÊôÓÚÃô¸ÐÐÅÏ¢ ¡£Ò»µ©ÕâЩÐÅÏ¢ÃæÁÙй¶ £¬Ð¡ÎÒ˽¼ÒÒþ˽Êܵ½ÖØ´óÍþвʱ £¬ºÃ±È´æ´¢ÓÐÕâЩÐÅÏ¢µÄÅÌËã»ú×°±¸É¥Ê§»ò²»µÃ²»ÇëËûÈËάÐÞʱ £¬³£Ê¹ÓÃÈ«´ÅÅ̼ÓÃÜÊÖÒÕÀ´½â¾öÕâЩÎÊÌâ ¡£¹ØÓÚÆóÒµ¿Í»§»ò×éÖ¯À´Ëµ £¬Ðí¶àÖ÷ÒªµÄÉÌÒµÉñÃØÎļþ»òÕþ²ßÎļþÒ»µ©Ð¹Â¶¾Í»á¸øÆóÒµºÍ×éÖ¯´øÀ´ÖØ´óËðʧ ¡£´ÓһЩÊÓ²ìÀ´¿´ £¬ÆóÒµ»ò×éÖ¯µÄÅÌËã»ú×°±¸Ò»Ñùƽ³£²»»á±»ÍµÇÔ £¬¶øÆäÊý¾Ý鶵Äʱ»úÖ÷Òª±£´æÓÚ´¦Öóͷ£¾É×°±¸»ò¶ÔÅÌËã»ú×°±¸¾ÙÐÐάÐÞʱ ¡£È«´ÅÅ̼ÓÃÜÊÖÒÕ¿ÉÒÔÈÃÆóÒµ»ò×éÖ¯ÔÚ´¦Öóͷ£¾É×°±¸Ê±»ò¶Ô×°±¸¾ÙÐÐάÐÞʱ £¬×ÝÈ»ÃæÁÙÃô¸ÐÐÅϢ鶵ÄÍþвҲÎÞºó¹ËÖ®ÓÇ ¡£

ÏÖÔÚ³£¼ûµÄÈ«´ÅÅ̼ÓÃܲúÆ·½ÓÄɵļÓÃÜËã·¨¶àΪAES Ëã·¨ £¬ÕâÔÚº£ÄÚµÄһЩÏÖʵӦÓÃÖб£´æÕþ²ßΣº¦ ¡£ÎªÁËÖª×ãÕâÀàÏÖʵӦÓõÄÐèÇó £¬º£ÄڵIJÙ×÷ϵͳ³§ÉÌ»òÓ¦ÓÃÈí¼þ³§ÉÌ»áÍƳöʹÓùúÃÜSM4 µÄÈ«´ÅÅ̼ÓÃܹ¦Ð§µÄ²Ù×÷ϵͳ»òÓ¦ÓÃÈí¼þ ¡£¶øÔÚÔÚÕâЩʵÏÖÖÐ £¬È«´ÅÅ̼ÓÃܹ¦Ð§Ò»Ñùƽ³£¶¼ÊÇʵʱµÄ¼Ó½âÃÜÊý¾Ý £¬Õâ¶Ô¼Ó½âÃÜÀú³ÌµÄÐÔÄÜÒªÇóÊǺܸߵÄ £¬´Ëʱ¿ÉÒÔʹÓÃGMI ʵÏÖ¹úÃÜSM4 ÒÔÌæ»»¹Å°åµÄ´¿Èí¼þʵÏÖ £¬´Ó¶ø²»µ«ÄܱÜÃâËã·¨±»¸Ä¶¯ £¬»¹ÄÜÌá¸ßÔËËãËÙÂÊ ¡£


2)ÔÆÓ¦ÓÃ

¹¹½¨¿ÉÐÅÔÆƽ̨ʱ £¬µ±ÔÆÖÐÓжÔÊý¾Ý×ö¼ÓÃÜÏ¢ÕùÃÜÐèÇóµÄʱ¼ä £¬¿ÉÒÔʹÓÃGMI ʵÏÖ¹úÃÜSM4 Ìæ»»¹Å°åµÄ´¿Èí¼þʵÏÖ £¬´Ó¶ø²»µ«ÄܱÜÃâËã·¨±»¸Ä¶¯ £¬»¹ÄÜÌá¸ßÔËËãËÙÂÊ ¡£


3)Ó¦Óü¶¼ÓÃÜ

´ó²¿·ÖÆóÒµºÍÔÆÓ¦Óý«Ìṩ¶àÖÖÑ¡ÏîÀ´¶ÔÇå¾²ÐÅϢʹÓüÓÃÜÊÖÒÕ ¡£ºÃ±ÈÊý¾Ý¿â £¬Ó¦ÓÃЧÀÍÆ÷ £¬ÖÐÐļþ £¬ÓʼþЧÀÍÆ÷ÒÔ¼°ÐéÄâ»úÖÎÀí³ÌÐòµÈ¶¼»áÓõ½SM4 ¼ÓÃÜÊÖÒÕ ¡£´Ëʱ¶¼¿ÉÒÔͨ¹ýGMI SM4 Ó²¼þʵÏÖÀ´Ìæ»»¹Å°åµÄÈí¼þʵÏÖ ¡£


4.GMIÖ¸ÁîÏÈÈÝ


4.1 GMI SM3

GMI SM3»ù±¾Ö¸Áî¸Å¿ö£¨ÒÔ32λϵͳΪÀý£©ÈçϱíËùʾ£º

ͼ±í 8. GMI SM3»ù±¾Ö¸Áî¸Å¿ö£¨ÒÔ32λϵͳΪÀý£©

Ö¸Áî

CCS_HASH

Opcode

0xF3 0x0F 0xA6 0xE8

Input Register

EAX

µ±EAX=0 £¬ÔòÖ´ÐÐpadding;

µ±EAX=-1 £¬Ôò²»Ö´ÐÐpadding ¡£

EBX

¼´ÊÇ0x20 £¬ÔòÒÔΪSM3 Function±»Ê¹ÄÜ ¡£

ECX

ÊäÈëmessageµÄ´óÐ ¡£º

µ±EAX=0 £¬ÒÔbyteΪµ¥Î»ÅÌËã £»

µ±EAX=-1 £¬ÒÔblock£¨ 64 bytes£©Îªµ¥Î»ÅÌËã ¡£

RSI

Ö¸ÏòÊäÈëµÄmassage ¡£

RDI

Ö¸Ïò´æ·Å³õʼժҪֵµÄÄÚ´æ¿Õ¼ä ¡£

Output Register

EAX

µ±EAX=0 £¬ÔòÖ´ÐÐÍêÖ¸Áîºó £¬EAX¼´ÊÇECX £»

µ±EAX=-1 £¬ÔòÎȹ̻¯ ¡£

EBX

Îȹ̻¯ ¡£

ECX

µ±EAX=0 £¬ÔòÖ´ÐÐÍêÖ¸Áîºó £¬ECXÎȹ̻¯ £»

µ±EAX=-1 £¬ÔòECX=0 ¡£

ESI

Ö¸Ïò´ýÖ´ÐеÄÊý¾Ý ¡£

EDI

Îȹ̻¯ ¡£×îÖÕÅÌËã³öÀ´µÄÕªÒªÖµ´æ·ÅÓڸõصãÖ¸ÏòµÄÄÚ´æ¿Õ¼ä ¡£


4.2 GMI SM4

GMI SM4»ù±¾Ö¸Áî¸Å¿ö£¨ÒÔ32λϵͳΪÀý£©ÈçϱíËùʾ£º

ͼ±í 9. GMI SM4»ù±¾Ö¸Áî¸Å¿ö£¨ÒÔ32λϵͳΪÀý£©

Ö¸Áî

CCS_ENCRYPT

Opcode

0xF3 0x0F 0xA7 0xF0

Input Register

EAX

µ±Bit[0]=0 £¬×ö¼ÓÃÜÔËËã £»µ±Bit[0]=1 £¬×ö½âÃÜÔËËã ¡£

Bit[5:1]=10000 £¬Ê¹ÄÜSM4¹¦Ð§ ¡£

Bit[10:6]:SM4ģʽѡÔñ

Bit 6: ECB mode

Bit 7: CBC mode

Bit 8: CFB mode

Bit 9: OFB mode

Bit 10: CTR mode

µ±Bit[11]=1 £¬Ö´ÐÐMAC²Ù×÷ £»²»È»²»Ö´ÐÐ ¡£ÇÒ½öÕë¶ÔCBCºÍCFBģʽÓÐÓà ¡£

EBX

Ö¸Ïòkey ¡£

ECX

Òª±»¼ÓÃÜ»ò½âÃܵÄÊý¾Ý³¤¶È ¡£µ¥Î»ÊÇ128-bitsµÄ¸öÊý ¡£

EDX

Ö¸ÏòIV ¡£

ESI

Ö¸ÏòÊäÈëmessage ¡£

EDI

Ö¸Ïò¼ÓÃÜ/½âÃÜЧ¹û ¡£

Output Register

EAX

Îȹ̻¯ ¡£

EBX

Îȹ̻¯ ¡£

ECX

0

ESI

Ö¸ÏòÄ¿½ñ´ýÖ´ÐеÄÊý¾Ý ¡£

EDI

Ö¸ÏòÄ¿½ñ¼ÓÃÜ/½âÃܵÄЧ¹û ¡£


5.GMIÈí¼þ½â¾ö¼Æ»®

ÏÖÔÚ £¬QG¹Î¹ÎÀÖÌṩÒÔÏÂÈýÖÖÈí¼þ½â¾ö¼Æ»®£º

1)ʹÓÃOpenSSL EVP½Ó¿ÚʹÓÃGMI £»

2)ʹÓÃ×ÔÁ¦ÓÚOpenSSL¼Ü¹¹µÄLinux¿ª·¢¿âʹÓÃGMI £»

3)ʹÓÃGMIÖ¸ÁîSample Code×ÔÖ÷±à³ÌʹÓÃGMI ¡£


5.1 ʹÓÃOpenSSL EVP½Ó¿ÚʹÓÃGMI

OpenSSLÊÇÐÅÏ¢Çå¾²ÁìÓòʹÓÃ×îΪÆÕ±éµÄÃÜÂëѧËã·¨Ö§³ÖÈí¼þ¿â £¬ËüΪLinux¡¢Windows¡¢BSD¡¢Mac¡¢VMSµÈϵͳÌṩÁ˸»ºñµÄÃÜÂëѧËã·¨Ö§³Ö ¡£OpenSSLÏÕЩ¿ÉÒÔ×÷ΪÐÅÏ¢Çå¾²ÁìÓòµÄ±ê×¼ÃÜÂë¿â ¡£Òò´ËʵÏÖ»ùÓÚOpenSSLµÄGMIŲÓÃÒâÒåÖØ´ó ¡£


5.1.1 For OpenSSL 1.0.x and 1.1.0x

»ùÓÚ1.0.x°æ±¾ºÍ1.1.0x°æ±¾OpenSSL £¬ÎÒÃÇʵÏÖÁ˽«GMIÒÔGMI EngineµÄ·½·¨Ìí¼Óµ½OpenSSLÖÐ ¡£

GMIÔ´ÂëÁ´½Ó:https://github.com/ZXOpenSource/OpenSSL-ZX-GMI

GITÏÂÔØ:git clone https://github.com/ZXOpenSource/OpenSSL-ZX-GMI.git

»ùÓÚ1.0.x°æ±¾OpenSSL £¬°üÀ¨GMI EngineµÄ×îдúÂëΪ£ºopenssl-1.0.2j-ZX-GMI-1.2.tar.gz ¡£

»ùÓÚ1.1.0x°æ±¾OpenSSL £¬°üÀ¨GMI EngineµÄ×îдúÂëΪ£ºopenssl-1.1.0e-ZX-GMI-1.1.tar.gz ¡£


5.1.2 For OpenSSL 1.1.1x

»ùÓÚ1.1.1x°æ±¾µÄOpenSSL £¬ÎÒÃǽ«GMI EngineºÏ²¢½øÔ­±¾¾Í±£´æÓÚOpenSSLµÄPadlock Engine £¬GMI Engine²»ÔÙÒÔµ¥¶ÀEngine±£´æ £¬¶øÊDZ»°üÀ¨½øPadlock EngineÀï ¡£ÏÖÔÚÕⲿ·Ö´úÂëÎÒÃÇÕýÔÚÍùOpenSSLÉçÇøÌá½» ¡£

»ùÓÚOpenSSL 1.1.1fÇÒ°üÀ¨ÁËGMIµÄÔ´Âë¿ÉÒÔÔÚÕâÀïÕÒµ½£º?

https://github.com/ZXOpenSource/OpenSSL-ZX-GMI

ΪÁ˽«Padlock Engine±àÒë½ølibcrypto.aÖÐ £¬ÇëÔÚ±àÒëOpenSSLµÄʱ¼äÏÔʽµØ¼ÓÉϱàÒëÑ¡Ïî-DPADLOCK_ASM ¡£


5.1.3µÚÈý·½Ó¦ÓóÌÐòͨ¹ýOpenSSLʹÓÃGMIµÄÒªÁì

ÎÒÃÇÊÇͨ¹ýOpenSSLµÄEVP½Ó¿ÚÀ´ÊµÏÖ¶ÔGMIÖ¸ÁîŲÓõÄ ¡£


5.1.3.1GMI SM3

µÚÒ»²½ £¬×¢²áGMI / Padlock Engine £»

? ? ? ? ʹÓÃOpenSSL×¢²á½Ó¿Ú£º

ENGINE_load_builtin_engines();

ENGINE_register_all_digests();?

µÚ¶þ²½ £¬Å²ÓÃGMI ¡£Ê¹ÓÃOpenSSL EVP HASH½Ó¿Ú £¬ºÃ±ÈÒÔÏÂËĸö½Ó¿Ú£º

SM3

int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl);

int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data, size_t count);

int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size);

int EVP_Digest(const void *data, size_t count, unsigned char *md, unsigned int *size, const EVP_MD *type, ENGINE *impl);


5.1.3.2GMI SM4

µÚÒ»²½ £¬×¢²áGMI / Padlock Engine £»

? ? ? ? ʹÓÃOpenSSL×¢²á½Ó¿Ú£º

ENGINE_load_builtin_engines();

ENGINE_register_all_ciphers();

µÚ¶þ²½ £¬Å²ÓÃGMI ¡£Ê¹ÓÃOpenSSL EVP Encrypt/Decrypt½Ó¿Ú £¬ºÃ±ÈÒÔϽӿڣº

SM4 Encrypt

int EVP_EncryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl, const unsigned char *key, const unsigned char *iv);

int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, const unsigned char *in, int inl);

int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl);

int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *ctx, int pad);

SM4 Decrypt

int EVP_DecryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,?????????????????????? ENGINE *impl, const unsigned char *key, const unsigned char *iv);

int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, const unsigned char *in, int inl);

int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl);

int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *ctx, int pad);


5.2 ʹÓÃ×ÔÁ¦ÓÚOpenSSL¼Ü¹¹µÄLinux¿ª·¢¿âʹÓÃGMI

Ö»¹ÜOpenSSL ÊÇÒµ½ç×îÊ¢ÐеÄÃÜÂëѧËã·¨¿â £¬µ«ÉÐÓÐÐí¶àµÄÓ¦Óó¡¾°ÊÇOpenSSLÎÞ·¨Öª×ã»òÕß²»ÊʺϵÄ ¡£Òò´Ë £¬ÊµÏÖ»ùÓÚÖ÷Á÷²Ù×÷ϵͳLinuxµÄÏìÓ¦¿ª·¢¿âÄܹ»ÎªÓû§ÁíÍâÌṩһÖÖʹÓÃÖ§³ÖGMIµÄÑ¡Ôñ ¡£

ͨ¹ýÑо¿¹ú¼Ò/ÐÐÒµµÄÏà¹Ø±ê×¼ £¬µ÷ÑÐÒµ½ç¶Ô¼ÓÃÜ»ú/¼ÓÃÜ¿¨µÄÐèÌÖÇéÐÎ £¬ÎÒÃÇ×ܽáÌáÁ¶ÁËQG¹Î¹ÎÀÖ¹úÃÜËã·¨Ö¸Á·¢¿âµÄ½Ó¿ÚÐèÇó £¬Éè¼ÆÁË»ùÓÚQG¹Î¹ÎÀÖ¹úÃÜËã·¨Ö¸ÁîµÄLinux¿ª·¢¿âµÄÕûÌå¼Ü¹¹²¢»ùÓڸÿâ¸ø³öÁËÓ¦ÓÃÀý³ÌµÄdemo £¬ÓÃÒÔչʾͨ¹ýLinux¿ª·¢¿âʹÓÃQG¹Î¹ÎÀÖ¹úÃÜËã·¨Ö¸ÁîµÄÒªÁì ¡£

QG¹Î¹ÎÀÖLinux¿ª·¢¿âÏÖÔÚËùÖ§³ÖµÄÔËÐÐÇéÐÎÊÇLinux 64λÇéÐÎ ¡£Æä¶ÔÍâÌṩÁ½¸öÎļþ £¬»®·ÖÊǶ¯Ì¬¿âlibgmi.soºÍgmi.h£¨Ò²¿ÉÒÔƾ֤¿Í»§µÄÐèÇó¶¨ÖƳÉÆäËûÐÎʽºÃ±È¾²Ì¬¿âlibgmi.aÐÎʽ£© ¡£

Linux¿ª·¢¿âºÍŲÓÃdemo¿ÉÒÔÔÚQG¹Î¹ÎÀÖ¹ÙÍøhttp://www.zhaoxin.com/»ñÈ¡ ¡£


5.2.1 GMI SM3

ÓëÇ°ÃæÌáµ½µÄËã·¨¿âOpenSSLÀàËÆ £¬ÎÒÃÇͨ¹ýLinux¿âµÄÐÎʽ¸øSM3Ëã·¨Ò²Ö÷ÒªÌṩÁËËĸö½Ó¿Úº¯Êý £¬»®·ÖÊÇ£º

int gmi_sm3_init()

¹¦Ð§£º³õʼ»¯SM3 £¬²¢ÅжϸÃƽ̨ÊÇ·ñÖ§³ÖGMIÖ¸Áî ¡£

ÊäÈ룺ÎÞ

Êä³ö£ºÎÞ

·µ»ØÖµ£º1-ÌåÏÖ³õʼ»¯ÀÖ³É

0-ÌåÏÖ³õʼ»¯Ê§°Ü

int gmi_sm3_update(const void *data_, size_t len)

¹¦Ð§£º ¶Ôlen bytes of data at *data×öSM3 updateÅÌËã ¡£ÓÃÓÚgmi_sm3_init()Ö®ºógmi_sm3_final()֮ǰ £¬¿ÉÒÔ¶à´ÎŲÓà £¬ÒÔÅÌËãÊèÉ¢ÔÚ²î±ðbufferµÄÊý¾Ý ¡£

ÊäÈ룺

const void *data_£ºÒªSM3µÄÊý¾ÝµØµã

size_t len£ºÒªSM3µÄÊý¾ÝµÄ³¤¶È £¬µ¥Î»byte

Êä³ö£ºÎÞ

·µ»ØÖµ£º1-ÌåÏÖÖ´ÐÐÀÖ³É

0-ÌåÏÖÖ´ÐÐʧ°Ü

int gmi_sm3_final(unsigned char *md)

¹¦Ð§£ºSM3ÅÌËãµÄ×îºóÒ»²½

ÊäÈ룺ÎÞ

Êä³ö£º

unsigned char *md£ºÖ¸ÏòSM3µÄЧ¹û

·µ»ØÖµ£º1-ÌåÏÖÖ´ÐÐÀÖ³É

0-ÌåÏÖÖ´ÐÐʧ°Ü

int gmi_sm3(uint8_t *InBuf, uint64_t len, uint8_t *OutBuf)

?

¹¦Ð§£º´ÓInBufÊäÈëlen bytesÊý¾Ý×öSM3ÅÌËã £¬ÅÌËãЧ¹û·Åµ½OutBufÖ¸ÏòµÄ´æ´¢ÇøÓò ¡£

ÊäÈ룺

uint8_t *InBuf£ºÒªSM3µÄÊý¾ÝµØµã

uint64_t len£ºÒªSM3µÄÊý¾Ý³¤¶È £¬µ¥Î»byte

Êä³ö£º

uint8_t *OutBuf£ºÖ¸ÏòSM3µÄЧ¹û

·µ»ØÖµ£º1-ÌåÏÖÖ´ÐÐÀÖ³É

0-ÌåÏÖÖ´ÐÐʧ°Ü


5.2.2 GMI SM4

ÓëÇ°ÃæÌáµ½µÄËã·¨¿âOpenSSLÀàËÆ £¬ÎÒÃÇͨ¹ýLinux¿âµÄÐÎʽ¸øSM4Ëã·¨Ò²Ö÷ÒªÌṩÁËÎå¸ö½Ó¿Úº¯Êý £¬»®·ÖÊÇ£º

int SM4_Init(const unsigned int? cipher_mode, const unsigned char *key,const unsigned char *iv, int enc)

?

¹¦Ð§£º³õʼ»¯SM4ÅÌËã £¬²¢ÅжϸÃƽ̨ÊÇ·ñÖ§³ÖGMIÖ¸Áî ¡£

ÊäÈ룺

const unsigned int? cipher_mode£º¿ÉÊäÈëÖµÓУº

#define SM4_ECB_MODE 0x1

#define SM4_CBC_MODE 0x2

#define SM4_CFB_MODE 0x3

#define SM4_OFB_MODE 0x4

#define SM4_CTR_MODE 0x5

const unsigned char *key£º¼ÓÈëSM4ÅÌËãµÄkey

const unsigned char *iv£º¼ÓÈëSM4ÅÌËãµÄiv»òÕßcounter

int enc£º enc =1 £¬ÌåÏÖ¾ÙÐмÓÃÜÅÌËã £» enc =0 £¬ÌåÏÖ¾ÙÐнâÃÜÅÌËã

Êä³ö£ºÎÞ

·µ»ØÖµ£º1-ÌåÏÖÖ´ÐÐÀÖ³É

0-ÌåÏÖÖ´ÐÐʧ°Ü

int SM4_Update(unsigned char *out, int *outl, const unsigned char *in, int inl)

?

¹¦Ð§£º¶ÔinÊäÈëµÄinl bytesÊý¾Ý×öSM4 updateÅÌËã £¬Ð§¹ûΪout £¬³¤¶ÈΪoutl

ÊäÈ룺

unsigned char *out£ºupdateÅÌËãºóµÄÊä³ö £¬

int *outl£ºupdateÅÌËãºóÊä³öµÄ³¤¶È

const unsigned char *in£ºupdateÅÌËãµÄÊäÈëÊý¾Ý

int inl£ºupdateÅÌËãÊäÈëÊý¾ÝµÄ³¤¶È

Êä³ö£ºÎÞ

·µ»ØÖµ£º1-ÌåÏÖÖ´ÐÐÀÖ³É

0-ÌåÏÖÖ´ÐÐʧ°Ü

int SM4_Final(unsigned char *out, int *outl)

?

¹¦Ð§£ºSM4ÅÌËãµÄ×îºóÒ»²½

ÊäÈ룺ÎÞ

Êä³ö£º

unsigned char *out£ºÖ¸ÏòfinalÅÌËãµÄЧ¹û

int *outl£ºfinalÅÌËãЧ¹ûµÄ³¤¶È

·µ»ØÖµ£º1-ÌåÏÖÖ´ÐÐÀÖ³É

0-ÌåÏÖÖ´ÐÐʧ°Ü

int SM4_set_padding(int pad)

¹¦Ð§£ºÉèÖÃÊÇ·ñpaddingµÄflag

ÊäÈ룺

int pad£ºpad=1 £¬ÌåÏÖÐèÒªpadding £»pad=0 £¬ÌåÏÖ²»ÐèÒªpadding ¡£

Êä³ö£ºÎÞ

·µ»ØÖµ£º1-ÌåÏÖÖ´ÐÐÀÖ³É

0-ÌåÏÖÖ´ÐÐʧ°Ü

int gmi_sm4(unsigned char *in_data, int inl, unsigned char *iv, int mode, unsigned char *key, int encrypt, unsigned char *out_data,? int *outl)

?

¹¦Ð§£ºÊ¹³¤¶ÈΪinlµÄin_dataÊý¾Ý £¬ÃÜԿΪkey £¬iv»òÕßcounterΪiv £¬×öSM4-mode encrypt/decryptÅÌËã £¬×îÖÕЧ¹û·ÅÔÚout_data ¡£

ÊäÈ룺

unsigned char *in_data£ºÖ¸ÏòÊäÈëÊý¾Ý

int inl£ºÊäÈëÊý¾ÝµÄ³¤¶È

unsigned char *iv£ºÊäÈëiv»òÕßcounter

int mode£ºÄ£Ê½ £¬¿ÉÒÔ´ÓÒÔÏÂÎåÖÖģʽÖÐÑ¡Ôñ£º

#define SM4_ECB_MODE 0x1

#define SM4_CBC_MODE 0x2

#define SM4_CFB_MODE 0x3

#define SM4_OFB_MODE 0x4

#define SM4_CTR_MODE 0x5

unsigned char *key£ºkey

int encrypt£ºencrypt =1 £¬×ö¼ÓÃÜÅÌËã £»encrypt=0 £¬×ö½âÃÜÅÌËã

Êä³ö£º

unsigned char *out_data£ºÖ¸ÏòSM4ÅÌËãµÄЧ¹û

int *outl:Ч¹ûµÄ³¤¶È ¡£

·µ»ØÖµ£º1-ÌåÏÖÖ´ÐÐÀÖ³É

0-ÌåÏÖÖ´ÐÐʧ°Ü


5.3ʹÓÃGMIÖ¸ÁîSample Code×ÔÖ÷±à³ÌʹÓÃGMI?

ÈôÊÇÄú²»Ê¹ÓÃÇ°ÃæÕ½ÚÌáµ½µÄQG¹Î¹ÎÀÖGMIÈí¼þ½â¾ö¼Æ»® £¬Ï£ÍûÄܹ»×Ô¼º±à³ÌÀ´Ê¹ÓÃGMI £¬ËäȻҲÊÇ¿ÉÒ﵀ ¡£ÏÂÃ渽ÉÏGMIÖ¸ÁîÔÚ32λºÍ64λµÄsample code ¡£


5.3.1 GMI SM3

l? 32λϵͳ£º

.size??? gmi_sm3_oneshot,.-.L_gmi_sm3_oneshot_begin

.globl?? gmi_sm3_blocks

.type??? gmi_sm3_blocks,@function

.align?? 16

gmi_sm3_blocks:

.L_gmi_sm3_blocks_begin:

???? pushl??? %ebx

???? pushl??? %edi?

???? pushl??? %esi

???? movl 16(%esp),%edi

???? movl 20(%esp),%esi

???? movl 24(%esp),%ecx

???? movl %esp,%edx

???? addl $-128,%esp

???? movups?? (%edi),%xmm0

???? andl $-16,%esp

???? movups?? 16(%edi),%xmm1

???? movaps?? %xmm0,(%esp)

???? movl %esp,%edi

???? movaps?? %xmm1,16(%esp)

???? movl $32,%ebx

???? movl $-1,%eax

.byte??? 0xf3,0x0f,0xa6,0xe8

???? movaps?? (%esp),%xmm0

???? movaps?? 16(%esp),%xmm1

???? movl %edx,%esp

???? movl 16(%esp),%edi

???? movups?? %xmm0,(%edi)

???? movups?? %xmm1,16(%edi)

???? popl %esi

???? popl %edi

???? popl %ebx

???? ret

.size??? gmi_sm3_blocks,.-.L_gmi_sm3_blocks_begin

?

l? 64λϵͳ

.globl?? gmi_sm3_blocks

.type??? gmi_sm3_blocks,@function

.align?? 16

gmi_sm3_blocks:

???? movq %rbx,%r11

???? movq %rdx,%rcx

???? movq %rdi,%rdx

???? movups?? (%rdi),%xmm0

???? subq $128+8,%rsp

???? movups?? 16(%rdi),%xmm1

???? movaps?? %xmm0,(%rsp)

???? movq %rsp,%rdi

???? movaps?? %xmm1,16(%rsp)

???? movq $32,%rbx

???? movq $-1,%rax

.byte??? 0xf3,0x0f,0xa6,0xe8

???? movaps?? (%rsp),%xmm0

???? movaps?? 16(%rsp),%xmm1

???? addq $128+8,%rsp

???? movups?? %xmm0,(%rdx)

???? movups?? %xmm1,16(%rdx)

???? movq %r11,%rbx

???? .byte??? 0xf3,0xc3

.size??? gmi_sm3_blocks,.-gmi_sm3_blocks


5.3.2 GMI SM4

l? 32λϵͳ£º

.globl?? gmi_gx6_sm4_encrypt

.type??? gmi_gx6_sm4_encrypt,@function

.align?? 16

gmi_gx6_sm4_encrypt:

.L_gmi_gx6_sm4_encrypt_begin:

???? pushl??? %ebx

???? pushl??? %edi

???? pushl??? %esi

???? movl 16(%esp),%edi

???? movl 20(%esp),%esi

???? movl 24(%esp),%edx

???? movl 28(%esp),%ecx

???? leal 32(%edx),%ebx

???? shrl $4,%ecx

???? movl 16(%edx),%eax

.byte??? 0xf3,0x0f,0xa7,0xf0

???? popl %esi

???? popl %edi

???? popl %ebx

???? ret

.size??? gmi_gx6_sm4_encrypt,.-.L_gmi_gx6_sm4_encrypt_begin


l? 64λϵͳ£º

.globl? gmi_gx6_sm4_encrypt

.type?? gmi_gx6_sm4_encrypt,@function

.align? 16

gmi_gx6_sm4_encrypt:

??? pushq?? %rbp

??? pushq?? %rbx

??? pushq?? %rdi

??? pushq?? %rsi

??? leaq 32(%rdx),%rbx

??? shrq $4,%rcx

??? movq 16(%rdx),%rax

.byte?? 0xf3,0x0f,0xa7,0xf0

??? popq %rsi

??? popq %rdi

??? popq %rbx

??? popq %rbp

??? .byte?? 0xf3,0xc3

.size?? gmi_gx6_sm4_encrypt,.-gmi_gx6_sm4_encrypt

ÍƼö²úÆ·

ÑлªIPC-610¹¤ÒµµçÄÔ
»ùÓÚQG¹Î¹ÎÀÖ¿ªÏÈ? KX-6000 ϵÁд¦Öóͷ£Æ÷
ÑÐÏéIPC-710¹¤ÒµµçÄÔ
»ùÓÚQG¹Î¹ÎÀÖ¿ªÏÈ? ZX-C+ ϵÁд¦Öóͷ£Æ÷