[SM国密算法][OpenSSL] PBOC Offline Data验证之DDA

//DDA
//////////////////////////////////////////////////////////////////////////
void CLibTesterDlg::VerifyIssuserPublicKeyWithSignature_DDA()
{
    VerifyIssuserPublicKeyWithSignature_SDA();
}

void CLibTesterDlg::VerifyIccPublicKeyWithSignature_DDA()
{
    //PBOC
    //////////////////////////////////////////////////////////////////////////
    //Step 1 (Issuer public key)
    BYTE byPublicKeyXA[32] = {0x9F, 0x48, 0x3B, 0xF2, 0xCC, 0x71, 0xC5, 0x09, 0x37, 0x28, 0x31, 0x80, 0x61, 0xE3, 0xF7, 0x68,
                              0xEA, 0x7C, 0x17, 0x0F, 0x82, 0xDD, 0x8C, 0x4B, 0x97, 0x9F, 0xBD, 0x8C, 0x76, 0xA1, 0x29, 0xF9};
    BYTE byPublicKeyYA[32] = {0x3F, 0xB5, 0x74, 0x6E, 0x96, 0xF5, 0xE4, 0x9B, 0x98, 0x7F, 0xFB, 0x52, 0x1E, 0x47, 0x3B, 0x25,
                              0xE1, 0xB0, 0x17, 0xC3, 0x0B, 0xE3, 0xFC, 0x63, 0x8B, 0xA1, 0x4D, 0x5F, 0xA4, 0xAA, 0xDC, 0x16};
    SetupBasiSMAlgorithm(byPublicKeyXA, byPublicKeyYA);

    //Step 2
    BYTE byHash[32] = {0};
    SM3_GenZaHash(byHash);

    //Step 3
    BYTE byData[] = {0x14,
                     0x62, 0x28, 0x00, 0x01, 0x00, 0x00, 0x11, 0x17, 0xFF, 0xFF,
                     0x12, 0x20,
                     0x00, 0x00, 0x10,
                     0x04,
                     0x00,
                     0x11,
                     0x40,
                     0xC3, 0xAC, 0x12, 0xB8, 0x1B, 0x9D, 0x17, 0x59, 0x36, 0xB5, 0xBF, 0x72, 0xBB, 0x8F, 0xE3, 0xA2,
                     0x26, 0x6B, 0xC0, 0x13, 0xB2, 0xE9, 0x4F, 0x58, 0x37, 0xF1, 0x6A, 0xA1, 0xC0, 0x1A, 0xA7, 0x32,
                     0x3B, 0x75, 0x62, 0x6A, 0xB6, 0x4D, 0x02, 0xAE, 0xD2, 0x0C, 0xC6, 0xF4, 0x40, 0x84, 0x1F, 0x10,
                     0xEE, 0x68, 0x73, 0xBC, 0xBE, 0xA3, 0xF4, 0x1D, 0x68, 0x69, 0xD0, 0xFE, 0xAD, 0xD7, 0x11, 0x54,
                     0x5A, 0x08, 0x62, 0x28, 0x00, 0x01, 0x00, 0x00, 0x11, 0x17, 0x5F, 0x34, 0x01, 0x01};
    BYTE byR[32] =  {0xDC, 0x5F, 0xE8, 0x6C, 0xF9, 0x11, 0x54, 0x4D, 0x97, 0x29, 0xF3, 0x7C, 0x26, 0xBB, 0xBF, 0xB0,
                     0x6A, 0x75, 0xF1, 0x7C, 0xF8, 0x28, 0x2E, 0xA2, 0xA4, 0x02, 0x74, 0xF4, 0x57, 0x7B, 0xB3, 0x83};
    BYTE byS[32] =  {0xE0, 0xC9, 0x1E, 0xE4, 0xFE, 0x27, 0xAA, 0x4D, 0xE9, 0xDD, 0x12, 0xA5, 0x63, 0x1C, 0xA4, 0x05,
                     0xC3, 0x47, 0x50, 0x74, 0x9F, 0x72, 0x66, 0xC4, 0xFC, 0xB3, 0x7A, 0x1A, 0xFC, 0x48, 0x4C, 0x04};
    BYTE byFullData[1024] = {0};
    int nFillLen = 0;

    memcpy(byFullData, byHash, 32);
    nFillLen += 32;
    memcpy(byFullData+nFillLen, byData, sizeof(byData));
    nFillLen += sizeof(byData);
    SM3(byFullData, nFillLen, byHash); //Get Hash for Signature

    BOOL bRet = SM2_VerifySignature(byHash, 32, byR, byS);

    CString strLog;
    GetDlgItem(IDC_LOG_EDIT)->GetWindowText(strLog);
    if (bRet)
    {
        strLog += _T("VerifyIccPublicKeyWithSignature OK!\r\n");
    }
    else
    {
        strLog += _T("VerifyIccPublicKeyWithSignature Failed!\r\n");
    }
    GetDlgItem(IDC_LOG_EDIT)->SetWindowText(strLog);
}

void CLibTesterDlg::VerifyInternalAuthDataWithSignature_DDA()
{
    //PBOC
    //////////////////////////////////////////////////////////////////////////
    //Step 1 (Issuer public key)
    BYTE byPublicKeyXA[32] = {0xC3, 0xAC, 0x12, 0xB8, 0x1B, 0x9D, 0x17, 0x59, 0x36, 0xB5, 0xBF, 0x72, 0xBB, 0x8F, 0xE3, 0xA2,
                              0x26, 0x6B, 0xC0, 0x13, 0xB2, 0xE9, 0x4F, 0x58, 0x37, 0xF1, 0x6A, 0xA1, 0xC0, 0x1A, 0xA7, 0x32};
    BYTE byPublicKeyYA[32] = {0x3B, 0x75, 0x62, 0x6A, 0xB6, 0x4D, 0x02, 0xAE, 0xD2, 0x0C, 0xC6, 0xF4, 0x40, 0x84, 0x1F, 0x10,
                              0xEE, 0x68, 0x73, 0xBC, 0xBE, 0xA3, 0xF4, 0x1D, 0x68, 0x69, 0xD0, 0xFE, 0xAD, 0xD7, 0x11, 0x54};
    SetupBasiSMAlgorithm(byPublicKeyXA, byPublicKeyYA);

    //Step 2
    BYTE byHash[32] = {0};
    SM3_GenZaHash(byHash);

    //Step 3
    BYTE byData[] = {0x15,
                     0x07,
                     0x06, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66,
                     0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
                     0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                     0x01, 0x56,
                     0x00, 0x00, 0x00, 0x00, 0x00,
                     0x01, 0x56,
                     0x12, 0x03, 0x03,
                     0x00, 0x1E, 0x5E, 0x10, 0xA1};
    BYTE byR[32] =  {0xDA, 0x45, 0x36, 0xAB, 0x67, 0x22, 0x5E, 0x7E, 0x23, 0x86, 0x7D, 0x30, 0xD6, 0xDA, 0x83, 0x3A,
                     0x5B, 0x6A, 0xE0, 0x68, 0x76, 0xB0, 0x91, 0xA7, 0xDE, 0x65, 0x7C, 0xDF, 0x4D, 0x39, 0xB8, 0x19};
    BYTE byS[32] =  {0x64, 0x47, 0x22, 0x5D, 0xF8, 0x87, 0x3B, 0x24, 0x5D, 0x7B, 0x68, 0x0F, 0x41, 0xA7, 0x4A, 0x03,
                     0x5E, 0x95, 0x82, 0xC2, 0xB2, 0x0D, 0x2C, 0x22, 0xE1, 0xDE, 0x3D, 0x2F, 0xAD, 0xE8, 0xCD, 0x60};
    BYTE byFullData[1024] = {0};
    int nFillLen = 0;

    memcpy(byFullData, byHash, 32);
    nFillLen += 32;
    memcpy(byFullData+nFillLen, byData, sizeof(byData));
    nFillLen += sizeof(byData);
    SM3(byFullData, nFillLen, byHash); //Get Hash for Signature

    BOOL bRet = SM2_VerifySignature(byHash, 32, byR, byS);

    CString strLog;
    GetDlgItem(IDC_LOG_EDIT)->GetWindowText(strLog);
    if (bRet)
    {
        strLog += _T("VerifyInternalAuthDataWithSignature OK!\r\n");
    }
    else
    {
        strLog += _T("VerifyInternalAuthDataWithSignature Failed!\r\n");
    }
    GetDlgItem(IDC_LOG_EDIT)->SetWindowText(strLog);
}

void CLibTesterDlg::VerifyIssuserPublicKeyWithSignature2_DDA()
{
     VerifyIssuserPublicKeyWithSignature2_SDA();
}

void CLibTesterDlg::VerifyIccPublicKeyWithSignature2_DDA()
{
    //PBOC
    //////////////////////////////////////////////////////////////////////////
    //Step 1 (Issuer public key)
    BYTE byPublicKeyXA[32] = {0x9F, 0x48, 0x3B, 0xF2, 0xCC, 0x71, 0xC5, 0x09, 0x37, 0x28, 0x31, 0x80, 0x61, 0xE3, 0xF7, 0x68,
                              0xEA, 0x7C, 0x17, 0x0F, 0x82, 0xDD, 0x8C, 0x4B, 0x97, 0x9F, 0xBD, 0x8C, 0x76, 0xA1, 0x29, 0xF9};
    BYTE byPublicKeyYA[32] = {0x3F, 0xB5, 0x74, 0x6E, 0x96, 0xF5, 0xE4, 0x9B, 0x98, 0x7F, 0xFB, 0x52, 0x1E, 0x47, 0x3B, 0x25,
                              0xE1, 0xB0, 0x17, 0xC3, 0x0B, 0xE3, 0xFC, 0x63, 0x8B, 0xA1, 0x4D, 0x5F, 0xA4, 0xAA, 0xDC, 0x16};
    SetupBasiSMAlgorithm(byPublicKeyXA, byPublicKeyYA);

    //Step 2
    BYTE byData[] = {0x14,
                     0x62, 0x28, 0x00, 0x01, 0x00, 0x00, 0x11, 0x17, 0xFF, 0xFF,
                     0x12, 0x20,
                     0x00, 0x00, 0x10,
                     0x04,
                     0x00,
                     0x11,
                     0x40,
                     0xC3, 0xAC, 0x12, 0xB8, 0x1B, 0x9D, 0x17, 0x59, 0x36, 0xB5, 0xBF, 0x72, 0xBB, 0x8F, 0xE3, 0xA2,
                     0x26, 0x6B, 0xC0, 0x13, 0xB2, 0xE9, 0x4F, 0x58, 0x37, 0xF1, 0x6A, 0xA1, 0xC0, 0x1A, 0xA7, 0x32,
                     0x3B, 0x75, 0x62, 0x6A, 0xB6, 0x4D, 0x02, 0xAE, 0xD2, 0x0C, 0xC6, 0xF4, 0x40, 0x84, 0x1F, 0x10,
                     0xEE, 0x68, 0x73, 0xBC, 0xBE, 0xA3, 0xF4, 0x1D, 0x68, 0x69, 0xD0, 0xFE, 0xAD, 0xD7, 0x11, 0x54,
                     0x5A, 0x08, 0x62, 0x28, 0x00, 0x01, 0x00, 0x00, 0x11, 0x17, 0x5F, 0x34, 0x01, 0x01};
    BYTE byR[32] =  {0xDC, 0x5F, 0xE8, 0x6C, 0xF9, 0x11, 0x54, 0x4D, 0x97, 0x29, 0xF3, 0x7C, 0x26, 0xBB, 0xBF, 0xB0,
                     0x6A, 0x75, 0xF1, 0x7C, 0xF8, 0x28, 0x2E, 0xA2, 0xA4, 0x02, 0x74, 0xF4, 0x57, 0x7B, 0xB3, 0x83};
    BYTE byS[32] =  {0xE0, 0xC9, 0x1E, 0xE4, 0xFE, 0x27, 0xAA, 0x4D, 0xE9, 0xDD, 0x12, 0xA5, 0x63, 0x1C, 0xA4, 0x05,
                     0xC3, 0x47, 0x50, 0x74, 0x9F, 0x72, 0x66, 0xC4, 0xFC, 0xB3, 0x7A, 0x1A, 0xFC, 0x48, 0x4C, 0x04};

    BOOL bRet = SM2_VerifySignature2(byData, sizeof(byData), byR, byS);

    CString strLog;
    GetDlgItem(IDC_LOG_EDIT)->GetWindowText(strLog);
    if (bRet)
    {
        strLog += _T("VerifyIccPublicKeyWithSignature2 OK!\r\n");
    }
    else
    {
        strLog += _T("VerifyIccPublicKeyWithSignature2 Failed!\r\n");
    }
    GetDlgItem(IDC_LOG_EDIT)->SetWindowText(strLog);
}

void CLibTesterDlg::VerifyInternalAuthDataWithSignature2_DDA()
{
    //PBOC
    //////////////////////////////////////////////////////////////////////////
    //Step 1 (Issuer public key)
    BYTE byPublicKeyXA[32] = {0xC3, 0xAC, 0x12, 0xB8, 0x1B, 0x9D, 0x17, 0x59, 0x36, 0xB5, 0xBF, 0x72, 0xBB, 0x8F, 0xE3, 0xA2,
                              0x26, 0x6B, 0xC0, 0x13, 0xB2, 0xE9, 0x4F, 0x58, 0x37, 0xF1, 0x6A, 0xA1, 0xC0, 0x1A, 0xA7, 0x32};
    BYTE byPublicKeyYA[32] = {0x3B, 0x75, 0x62, 0x6A, 0xB6, 0x4D, 0x02, 0xAE, 0xD2, 0x0C, 0xC6, 0xF4, 0x40, 0x84, 0x1F, 0x10,
                              0xEE, 0x68, 0x73, 0xBC, 0xBE, 0xA3, 0xF4, 0x1D, 0x68, 0x69, 0xD0, 0xFE, 0xAD, 0xD7, 0x11, 0x54};
    SetupBasiSMAlgorithm(byPublicKeyXA, byPublicKeyYA);

    //Step 2
    BYTE byData[] = {0x15,
                     0x07,
                     0x06, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66,
                     0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
                     0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                     0x01, 0x56,
                     0x00, 0x00, 0x00, 0x00, 0x00,
                     0x01, 0x56,
                     0x12, 0x03, 0x03,
                     0x00, 0x1E, 0x5E, 0x10, 0xA1};
    BYTE byR[32] =  {0xDA, 0x45, 0x36, 0xAB, 0x67, 0x22, 0x5E, 0x7E, 0x23, 0x86, 0x7D, 0x30, 0xD6, 0xDA, 0x83, 0x3A,
                     0x5B, 0x6A, 0xE0, 0x68, 0x76, 0xB0, 0x91, 0xA7, 0xDE, 0x65, 0x7C, 0xDF, 0x4D, 0x39, 0xB8, 0x19};
    BYTE byS[32] =  {0x64, 0x47, 0x22, 0x5D, 0xF8, 0x87, 0x3B, 0x24, 0x5D, 0x7B, 0x68, 0x0F, 0x41, 0xA7, 0x4A, 0x03,
                     0x5E, 0x95, 0x82, 0xC2, 0xB2, 0x0D, 0x2C, 0x22, 0xE1, 0xDE, 0x3D, 0x2F, 0xAD, 0xE8, 0xCD, 0x60};

    BOOL bRet = SM2_VerifySignature2(byData, sizeof(byData), byR, byS);

    CString strLog;
    GetDlgItem(IDC_LOG_EDIT)->GetWindowText(strLog);
    if (bRet)
    {
        strLog += _T("VerifyInternalAuthDataWithSignature2 OK!\r\n");
    }
    else
    {
        strLog += _T("VerifyInternalAuthDataWithSignature2 Failed!\r\n");
    }
    GetDlgItem(IDC_LOG_EDIT)->SetWindowText(strLog);
}

你可能感兴趣的:(OpenSSL)