<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Alen,  in Intel® Integrated Performance Primitives</title>
    <link>https://community.intel.com/t5/Intel-Integrated-Performance/Undefined-Behaviour-with-ippsModInv-BN/m-p/1120287#M25560</link>
    <description>&lt;P&gt;&lt;SPAN style="font-size: 12px; line-height: 18px;"&gt;Alen,&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;Thanks for checking it. &amp;nbsp;We are looking at this problem, and will provide you an update.&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
	Chao&lt;/P&gt;</description>
    <pubDate>Mon, 09 May 2016 03:22:27 GMT</pubDate>
    <dc:creator>Chao_Y_Intel</dc:creator>
    <dc:date>2016-05-09T03:22:27Z</dc:date>
    <item>
      <title>Undefined Behaviour with ippsModInv_BN</title>
      <link>https://community.intel.com/t5/Intel-Integrated-Performance/Undefined-Behaviour-with-ippsModInv-BN/m-p/1120286#M25559</link>
      <description>&lt;P&gt;Dear Intel Community,&lt;/P&gt;

&lt;P&gt;I am trying to compute the&amp;nbsp;&lt;SPAN style="font-size: 13.008px; line-height: 19.512px;"&gt;multiplicative inverse of two numbers, using&amp;nbsp;ippsModInv_BN. However, I get an undefined b&lt;/SPAN&gt;ehaviour&lt;SPAN style="font-size: 13.008px; line-height: 19.512px;"&gt;, and incorrect results. The issue occurs when executing the following:&lt;/SPAN&gt;&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;#include &amp;lt;iostream&amp;gt;
#include &amp;lt;ippcore.h&amp;gt;
#include &amp;lt;ippcp.h&amp;gt;
#include &amp;lt;ipps.h&amp;gt;
#include &amp;lt;ippdefs.h&amp;gt;
#include &amp;lt;ippch.h&amp;gt;

// Use the BigNumber class available at &lt;A href="https://software.intel.com/en-us/node/503848" target="_blank"&gt;https://software.intel.com/en-us/node/503848&lt;/A&gt;
// And initialize the values similarly to &lt;A href="https://software.intel.com/en-us/node/503498" target="_blank"&gt;https://software.intel.com/en-us/node/503498&lt;/A&gt;
#include "xsample_bignum.h"

using namespace std;

void modInv (BigNumber&amp;amp; P, BigNumber&amp;amp; Q)
{

//  Calculate the multiplicative inverse of a positive integer - big number Q
//  with respect to specified modulus P, using the same routine as implemented
//  in xsample_bignum.cpp
//
//  BigNumber BigNumber::InverseMul(const BigNumber&amp;amp; a) const
//  {
//      BigNumber r(*this);
//      ippsModInv_BN(BN(a), BN(*this), BN(r));
//      return r;
//  }

    BigNumber R(P);
    IppStatus status = ippsModInv_BN(BN(Q), BN(P), BN(R));

    cout &amp;lt;&amp;lt; "Status: ";
    switch (status) {
        case ippStsNoErr         : cout &amp;lt;&amp;lt; "ippStsNoErr"         &amp;lt;&amp;lt; endl; break;
        case ippStsBadArgErr     : cout &amp;lt;&amp;lt; "ippStsBadArgErr"     &amp;lt;&amp;lt; endl; break;
        case ippStsNullPtrErr    : cout &amp;lt;&amp;lt; "ippStsNullPtrErr"    &amp;lt;&amp;lt; endl; break;
        case ippStsBadModulusErr : cout &amp;lt;&amp;lt; "ippStsBadModulusErr" &amp;lt;&amp;lt; endl; break;
        case ippStsOutOfRangeErr : cout &amp;lt;&amp;lt; "ippStsOutOfRangeErr" &amp;lt;&amp;lt; endl; break;
        default:
            cout &amp;lt;&amp;lt; "Unknown error code: " &amp;lt;&amp;lt; status &amp;lt;&amp;lt; endl;
    }

    cout &amp;lt;&amp;lt; "P: " &amp;lt;&amp;lt; P &amp;lt;&amp;lt; endl;
    cout &amp;lt;&amp;lt; "Q: " &amp;lt;&amp;lt; Q &amp;lt;&amp;lt; endl;
    cout &amp;lt;&amp;lt; "R: " &amp;lt;&amp;lt; R &amp;lt;&amp;lt; endl;
    cout &amp;lt;&amp;lt; endl &amp;lt;&amp;lt; endl;
}

void test1 ()
{
    BigNumber P("0x098A0803974924E2671D9091044FE4ED0A6BA0978A9651D84EC5D2F97E3615CD555D504DD81B5832F884829D914ABD8AFEE8608A851AF569C3520C47E4D35646F");
    BigNumber Q("0x0BC612FF163A36AD648521120507CD2D4ADFC5DAC68856F6B45BBF101EFDB4A8D4656E8E2099C1DC3B7CFA16F57192ACA707E0C41E499837758E7A28E54BA6317");
    modInv(P, Q);

    // Expected:
    // 0x7F705DA34BC5CD9030BB4B5D0E4B2DEAC5734DD140076FA07C09B913F9C92B707247245BD0A96BD03EF1A84B11856519F8AB9247DC331C7B11A6B1636125AD16

    // Obtained:
    // 0x98A0803974924E2671D9091044FE4ED0A6BA0978A9651D84EC5D2F97E3615CD555D504DD81B5832F884829D914ABD8AFEE8608A851AF569C3520C47E4D35646F
}

void test2 ()
{
    BigNumber P("0x0BC612FF163A36AD648521120507CD2D4ADFC5DAC68856F6B45BBF101EFDB4A8D4656E8E2099C1DC3B7CFA16F57192ACA707E0C41E499837758E7A28E54BA6317");
    BigNumber Q("0x0B7EE5771917C2E470D42E54F8D40BE052BFA0413CC90E8DF14D983E1F490B6FE4B1856996417A0A5BDE8383BE18638D1A9DEC06E2E9386A289D6A1250D492973");
    modInv(P, Q);

    // Expected:
    // 0x5E73BECF77A0BE120FC9A1F7DBB69719755630772A95B840344737429CCAAB7E9D291B3E6E569EEDAEB92C88A389D4A50C8EEA795C5BB10401CA355878C72432

    // Obtained:
    // 0x5E73BECF77A0BE120FC9A1F7DBB69719755630772A95B840344737429CCAAB7E9D291B3E6E569EEDAEB92C88A389D4A50C8EEA795C5BB10401CA355878C72432
}

int main () {

    ippInit();
    cout &amp;lt;&amp;lt; "Using Intel IPP Crypto" &amp;lt;&amp;lt; endl;
    const IppLibraryVersion * version = ippsGetLibVersion ();
    printf("%s %s %s\n", version-&amp;gt;Name, version-&amp;gt;Version, version-&amp;gt;BuildDate);
    cout &amp;lt;&amp;lt; "================================================" &amp;lt;&amp;lt; endl;

    test1 ();
    test2 ();
    return 0;
}&lt;/PRE&gt;

&lt;P&gt;The problem occurs in the first test case (test1), and instead of the correct result, I get the same value of P. Furthermore, the status that is returned by &lt;SPAN style="font-size: 13.008px; line-height: 19.512px;"&gt;ippsModInv_BN&lt;/SPAN&gt;&amp;nbsp;is -13, which does not correspond to the expected return values. The output that I obtain is the following:&lt;/P&gt;

&lt;PRE class="brush:plain;"&gt;Using Intel IPP Crypto
ippSP AVX (e9) 9.0.3 (r51269) Apr  8 2016
================================================

Uknown error code: -13
P:  0x98A0803974924E2671D9091044FE4ED0A6BA0978A9651D84EC5D2F97E3615CD555D504DD81B5832F884829D914ABD8AFEE8608A851AF569C3520C47E4D35646F
Q:  0xBC612FF163A36AD648521120507CD2D4ADFC5DAC68856F6B45BBF101EFDB4A8D4656E8E2099C1DC3B7CFA16F57192ACA707E0C41E499837758E7A28E54BA6317
R:  0x98A0803974924E2671D9091044FE4ED0A6BA0978A9651D84EC5D2F97E3615CD555D504DD81B5832F884829D914ABD8AFEE8608A851AF569C3520C47E4D35646F

ippStsNoErr
P:  0xBC612FF163A36AD648521120507CD2D4ADFC5DAC68856F6B45BBF101EFDB4A8D4656E8E2099C1DC3B7CFA16F57192ACA707E0C41E499837758E7A28E54BA6317
Q:  0xB7EE5771917C2E470D42E54F8D40BE052BFA0413CC90E8DF14D983E1F490B6FE4B1856996417A0A5BDE8383BE18638D1A9DEC06E2E9386A289D6A1250D492973
R:  0x5E73BECF77A0BE120FC9A1F7DBB69719755630772A95B840344737429CCAAB7E9D291B3E6E569EEDAEB92C88A389D4A50C8EEA795C5BB10401CA355878C72432&lt;/PRE&gt;

&lt;P&gt;Is there any workaround for this issue ?&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
	Alen&lt;/P&gt;</description>
      <pubDate>Sat, 07 May 2016 01:28:34 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Integrated-Performance/Undefined-Behaviour-with-ippsModInv-BN/m-p/1120286#M25559</guid>
      <dc:creator>Alen_Stojanov</dc:creator>
      <dc:date>2016-05-07T01:28:34Z</dc:date>
    </item>
    <item>
      <title>Alen, </title>
      <link>https://community.intel.com/t5/Intel-Integrated-Performance/Undefined-Behaviour-with-ippsModInv-BN/m-p/1120287#M25560</link>
      <description>&lt;P&gt;&lt;SPAN style="font-size: 12px; line-height: 18px;"&gt;Alen,&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;Thanks for checking it. &amp;nbsp;We are looking at this problem, and will provide you an update.&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
	Chao&lt;/P&gt;</description>
      <pubDate>Mon, 09 May 2016 03:22:27 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Integrated-Performance/Undefined-Behaviour-with-ippsModInv-BN/m-p/1120287#M25560</guid>
      <dc:creator>Chao_Y_Intel</dc:creator>
      <dc:date>2016-05-09T03:22:27Z</dc:date>
    </item>
    <item>
      <title>Hi Alen,</title>
      <link>https://community.intel.com/t5/Intel-Integrated-Performance/Undefined-Behaviour-with-ippsModInv-BN/m-p/1120288#M25561</link>
      <description>&lt;P&gt;Hi Alen,&lt;/P&gt;

&lt;P&gt;It looks it has&amp;nbsp;some issues in the code.&lt;BR /&gt;
	-&amp;nbsp;In this case we deal with the ring Z/(p)&lt;BR /&gt;
	-&amp;nbsp;So, any element x of that ring should satisfy 0&amp;lt;=x&amp;lt;p&lt;/P&gt;

&lt;P&gt;In test1 we have:&lt;BR /&gt;
	p=0x098A0803974924E2671D9091044FE4ED0A6BA0978A9651D84EC5D2F97E3615CD555D504DD81B5832F884829D914ABD8AFEE8608A851AF569C3520C47E4D35646F&lt;BR /&gt;
	and&lt;BR /&gt;
	x=0x0BC612FF163A36AD648521120507CD2D4ADFC5DAC68856F6B45BBF101EFDB4A8D4656E8E2099C1DC3B7CFA16F57192ACA707E0C41E499837758E7A28E54BA6317&lt;/P&gt;

&lt;P&gt;x&amp;gt;p (and so x is not belongs to ring)&lt;BR /&gt;
	-&amp;nbsp;That is why the sample returns error status.&lt;/P&gt;

&lt;P&gt;The following code (similar to customer’s one, but correct with IPP’s point of view) looks the following:&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; // test1&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; BigNumber P1("0x098A0803974924E2671D9091044FE4ED0A6BA0978A9651D84EC5D2F97E3615CD555D504DD81B5832F884829D914ABD8AFEE8608A851AF569C3520C47E4D35646F");&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; BigNumber Q1("0x0BC612FF163A36AD648521120507CD2D4ADFC5DAC68856F6B45BBF101EFDB4A8D4656E8E2099C1DC3B7CFA16F57192ACA707E0C41E499837758E7A28E54BA6317");&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp; // make sure, that Q1 belongs to P1 ring&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; BigNumber R1 = P1.Modulo(Q1);&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; // compute multiplicative inversion&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; R1 = P1.InverseMul(R1);&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; cout &amp;lt;&amp;lt;"1/Q1 mod P1:" &amp;lt;&amp;lt;endl;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; cout &amp;lt;&amp;lt;R1 &amp;lt;&amp;lt;endl;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; // and test the result (R1*Q1) == 1 mod P1&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; BigNumber T1 = Q1*R1;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; T1 = P1.Modulo(T1);&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; cout &amp;lt;&amp;lt;"T1 = (Q1*R1) mod P1:" &amp;lt;&amp;lt;endl;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; cout &amp;lt;&amp;lt;T1 &amp;lt;&amp;lt;endl;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp; // test2&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; BigNumber P2("0x0BC612FF163A36AD648521120507CD2D4ADFC5DAC68856F6B45BBF101EFDB4A8D4656E8E2099C1DC3B7CFA16F57192ACA707E0C41E499837758E7A28E54BA6317");&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; BigNumber Q2("0x0B7EE5771917C2E470D42E54F8D40BE052BFA0413CC90E8DF14D983E1F490B6FE4B1856996417A0A5BDE8383BE18638D1A9DEC06E2E9386A289D6A1250D492973");&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp; // make sure, that Q2 belongs to P2 ring&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; BigNumber R2 = P2.Modulo(Q2);&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; // compute multiplicative inversion&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; R2 = P2.InverseMul(R2);&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; cout &amp;lt;&amp;lt;"1/Q2 mod P2:" &amp;lt;&amp;lt;endl;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; cout &amp;lt;&amp;lt;R2 &amp;lt;&amp;lt;endl;&lt;BR /&gt;
	&amp;nbsp; // and test the result (R2*Q2) == 1 mod P2&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; BigNumber T2 = Q2*R2;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; T2 = P2.Modulo(T2);&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; cout &amp;lt;&amp;lt;"T2 = (Q2*R2) mod P2:" &amp;lt;&amp;lt;endl;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; cout &amp;lt;&amp;lt;T2 &amp;lt;&amp;lt;endl;&lt;/P&gt;

&lt;P&gt;In result of execution we get&lt;BR /&gt;
	1/Q1 mod P1:&lt;BR /&gt;
	0x7F705DA34BC5CD9030BB4B5D0E4B2DEAC5734DD140076FA07C09B913F9C92B707247245BD0A96BD03EF1A84B11856519F8AB9247DC331C7B11A6B1636125AD16&lt;BR /&gt;
	T1 = (Q1*R1) mod P1:&lt;BR /&gt;
	0x00000001&lt;BR /&gt;
	1/Q2 mod P2:&lt;BR /&gt;
	0x5E73BECF77A0BE120FC9A1F7DBB69719755630772A95B840344737429CCAAB7E9D291B3E6E569EEDAEB92C88A389D4A50C8EEA795C5BB10401CA355878C72432&lt;BR /&gt;
	T2 = (Q2*R2) mod P2:&lt;BR /&gt;
	0x00000001&lt;/P&gt;

&lt;P&gt;so,&lt;BR /&gt;
	-&amp;nbsp;the inversion values (R1 and R2) are equals to expected&lt;BR /&gt;
	-&amp;nbsp;1==R1*Q1 mod P1 and 1== R2*Q2 mod P2 – so the computed values are correct&lt;/P&gt;

&lt;P&gt;&amp;nbsp;ippsModInv_BN() function itself is fine.&lt;/P&gt;

&lt;P&gt;That interpretation of “error” status is not very clear. we will look at how we can improve on this.&lt;BR /&gt;
	&lt;BR /&gt;
	Thanks,&lt;BR /&gt;
	Chao&lt;/P&gt;</description>
      <pubDate>Tue, 10 May 2016 07:59:21 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Integrated-Performance/Undefined-Behaviour-with-ippsModInv-BN/m-p/1120288#M25561</guid>
      <dc:creator>Chao_Y_Intel</dc:creator>
      <dc:date>2016-05-10T07:59:21Z</dc:date>
    </item>
  </channel>
</rss>

