You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@santuario.apache.org by Andrzej Matejko <an...@pro.onet.pl> on 2004/01/15 18:13:20 UTC

XSCryptCryptoBase64 - debug vs. release

Hi,

  I have discovered strange behavior of XSCryptCryptoBase64::encode
 in VisualC++.net.
  When I create xsec_1_0_0.dll in debug mode everything is ok
- encode works perfect, but when I have create release version....
something strange happend. Encode starts to create wrong output!! 
I have lost, lets say, 'some time' to discover that mistakes come from
this code:


		// First 6 bits;
		t = (m_inputBuffer[i] >> 2);

		// 2 bits from byte one and 4 from byte 2
		t = ((m_inputBuffer[i++] << 4) & 0x30) |
(m_inputBuffer[i] >> 4);
		m_outputBuffer[m_remainingOutput++] =
Base64LookupTable[t];

		// 4 from byte 2 and 2 from byte 3
		t = ((m_inputBuffer[i++] << 2) & 0x3C) |
(m_inputBuffer[i] >> 6);
		m_outputBuffer[m_remainingOutput++] =
Base64LookupTable[t];

		// last 6 bits from byte 3
		t = m_inputBuffer[i++] & 0x3F;
		m_outputBuffer[m_remainingOutput++] =
Base64LookupTable[t];


The problem is/was with '|' operator (I suppose).
So I have corrected this into something like that:

		// First 6 bits;
		t = (m_inputBuffer[i] >> 2);

		// 2 bits from byte one and 4 from byte 2
		//t = ((m_inputBuffer[i++] << 4) & 0x30) |
(m_inputBuffer[i] >> 4);
		t = ((m_inputBuffer[i] << 4) & 0x30);
		t |= (m_inputBuffer[i+1] >> 4);
		i++;
		m_outputBuffer[m_remainingOutput++] =
Base64LookupTable[t];

		// 4 from byte 2 and 2 from byte 3
		//t = ((m_inputBuffer[i++] << 2) & 0x3C) |
(m_inputBuffer[i] >> 6);
		t = ((m_inputBuffer[i] << 2) & 0x3C);
		t |= (m_inputBuffer[i+1] >> 6);
		i++;
		m_outputBuffer[m_remainingOutput++] =
Base64LookupTable[t];

		// last 6 bits from byte 3
		t = m_inputBuffer[i++] & 0x3F;
		m_outputBuffer[m_remainingOutput++] =
Base64LookupTable[t];


I know, that this is not 'a beautiful' code, but it works.
And here is my question: have I something wrong (wrong opitions,
declaration, etc.)
in my release project configuration in Visual? Maybe this is relevant to
type conversions?


  Best regards,
  AndrzeJ


Re: XSCryptCryptoBase64 - debug vs. release

Posted by Berin Lautenbach <be...@wingsofhermes.org>.
Andrzej,

Looks like VC++.net might be doing something strange in its 
optimisation.  I've never had any problems with a release version under 
VC6.0.

But my read of your code is it's exactly the same, just broken into two 
steps, so maybe the simplest thing would be to make this change 
permanent in the library.

(I like beautiful code most of the time - but I'll always go for the one 
that works if it comes to a choice :>)

Cheers,
	Berin


Andrzej Matejko wrote:

> Hi,
> 
>   I have discovered strange behavior of XSCryptCryptoBase64::encode
>  in VisualC++.net.
>   When I create xsec_1_0_0.dll in debug mode everything is ok
> - encode works perfect, but when I have create release version....
> something strange happend. Encode starts to create wrong output!! 
> I have lost, lets say, 'some time' to discover that mistakes come from
> this code:
> 
> 
> 		// First 6 bits;
> 		t = (m_inputBuffer[i] >> 2);
> 
> 		// 2 bits from byte one and 4 from byte 2
> 		t = ((m_inputBuffer[i++] << 4) & 0x30) |
> (m_inputBuffer[i] >> 4);
> 		m_outputBuffer[m_remainingOutput++] =
> Base64LookupTable[t];
> 
> 		// 4 from byte 2 and 2 from byte 3
> 		t = ((m_inputBuffer[i++] << 2) & 0x3C) |
> (m_inputBuffer[i] >> 6);
> 		m_outputBuffer[m_remainingOutput++] =
> Base64LookupTable[t];
> 
> 		// last 6 bits from byte 3
> 		t = m_inputBuffer[i++] & 0x3F;
> 		m_outputBuffer[m_remainingOutput++] =
> Base64LookupTable[t];
> 
> 
> The problem is/was with '|' operator (I suppose).
> So I have corrected this into something like that:
> 
> 		// First 6 bits;
> 		t = (m_inputBuffer[i] >> 2);
> 
> 		// 2 bits from byte one and 4 from byte 2
> 		//t = ((m_inputBuffer[i++] << 4) & 0x30) |
> (m_inputBuffer[i] >> 4);
> 		t = ((m_inputBuffer[i] << 4) & 0x30);
> 		t |= (m_inputBuffer[i+1] >> 4);
> 		i++;
> 		m_outputBuffer[m_remainingOutput++] =
> Base64LookupTable[t];
> 
> 		// 4 from byte 2 and 2 from byte 3
> 		//t = ((m_inputBuffer[i++] << 2) & 0x3C) |
> (m_inputBuffer[i] >> 6);
> 		t = ((m_inputBuffer[i] << 2) & 0x3C);
> 		t |= (m_inputBuffer[i+1] >> 6);
> 		i++;
> 		m_outputBuffer[m_remainingOutput++] =
> Base64LookupTable[t];
> 
> 		// last 6 bits from byte 3
> 		t = m_inputBuffer[i++] & 0x3F;
> 		m_outputBuffer[m_remainingOutput++] =
> Base64LookupTable[t];
> 
> 
> I know, that this is not 'a beautiful' code, but it works.
> And here is my question: have I something wrong (wrong opitions,
> declaration, etc.)
> in my release project configuration in Visual? Maybe this is relevant to
> type conversions?
> 
> 
>   Best regards,
>   AndrzeJ
> 
> 
>