Fixed // comments in c files (changed them to /* */ )
This commit is contained in:
19
intern/img/extern/IMG_Pixmap.h
vendored
19
intern/img/extern/IMG_Pixmap.h
vendored
@@ -51,12 +51,12 @@ public:
|
|||||||
/** The type of pixels that are stored in this pixmap. */
|
/** The type of pixels that are stored in this pixmap. */
|
||||||
typedef enum {
|
typedef enum {
|
||||||
kPixelTypeUnknown = 0, /**< R:8, G:8, B:8, Ignore:8 */
|
kPixelTypeUnknown = 0, /**< R:8, G:8, B:8, Ignore:8 */
|
||||||
// kPixelTypeRGB32 = 1, /**< R:8, G:8, B:8, Ignore:8 */
|
/* kPixelTypeRGB32 = 1, */ /*< R:8, G:8, B:8, Ignore:8 */
|
||||||
kPixelTypeRGBA32 = 2, /**< R:8, G:8, B:8, Alpha:8 */
|
kPixelTypeRGBA32 = 2, /**< R:8, G:8, B:8, Alpha:8 */
|
||||||
// kPixelTypeRGB16 = 3, /**< Ignore:1, R:5, G:5, B:5 */
|
/* kPixelTypeRGB16 = 3, */ /**< Ignore:1, R:5, G:5, B:5 */
|
||||||
// kPixelTypeRGBA16 = 4, /**< Alpha:1, R:5, G:5, B:5 */
|
/* kPixelTypeRGBA16 = 4, */ /**< Alpha:1, R:5, G:5, B:5 */
|
||||||
// kPixelTypeRGB16_565 = 5, /**< R:5, G:6, B:5 */
|
/* kPixelTypeRGB16_565 = 5, */ /**< R:5, G:6, B:5 */
|
||||||
// kPixelTypeRGB24 = 6 /**< R:8, G:8, B:8 */
|
/* kPixelTypeRGB24 = 6 */ /**< R:8, G:8, B:8 */
|
||||||
} TPixelType;
|
} TPixelType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -136,7 +136,7 @@ public:
|
|||||||
* @param r requested bounds rectangle in the image
|
* @param r requested bounds rectangle in the image
|
||||||
* @param c color to use
|
* @param c color to use
|
||||||
*/
|
*/
|
||||||
//virtual void fillRect(const GEN_Rect& r, const IMG_ColorRGBA& c) = 0;
|
/*virtual void fillRect(const GEN_Rect& r, const IMG_ColorRGBA& c) = 0; */
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/** Width of the image in pixels */
|
/** Width of the image in pixels */
|
||||||
@@ -149,8 +149,9 @@ protected:
|
|||||||
GEN_TUns32 m_pixelSize;
|
GEN_TUns32 m_pixelSize;
|
||||||
/** Type of pixels in this image. */
|
/** Type of pixels in this image. */
|
||||||
TPixelType m_pixelType;
|
TPixelType m_pixelType;
|
||||||
// TEndian m_bitOrder;
|
/* TEndian m_bitOrder;
|
||||||
// TEndian m_byteOrder;
|
TEndian m_byteOrder;
|
||||||
|
*/
|
||||||
};
|
};
|
||||||
|
|
||||||
inline GEN_TUns32 IMG_Pixmap::getWidth() const
|
inline GEN_TUns32 IMG_Pixmap::getWidth() const
|
||||||
@@ -195,4 +196,4 @@ inline void IMG_Pixmap::getPixelAddress(float u, float v, GEN_TInt32& x, GEN_TIn
|
|||||||
y = (GEN_TInt32)(((float)m_height) * v);
|
y = (GEN_TInt32)(((float)m_height) * v);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // _H_IMG_Pixmap
|
#endif /* _H_IMG_Pixmap */
|
||||||
|
10
intern/img/extern/IMG_PixmapRGBA32.h
vendored
10
intern/img/extern/IMG_PixmapRGBA32.h
vendored
@@ -178,14 +178,14 @@ inline IMG_PixmapRGBA32::TPixelPtr IMG_PixmapRGBA32::getPixelPtr(GEN_TUns32 x, G
|
|||||||
inline IMG_PixmapRGBA32::TPixelRGBA32 IMG_PixmapRGBA32::getPixelValue(const IMG_ColorRGBA& c) const
|
inline IMG_PixmapRGBA32::TPixelRGBA32 IMG_PixmapRGBA32::getPixelValue(const IMG_ColorRGBA& c) const
|
||||||
{
|
{
|
||||||
#if 0
|
#if 0
|
||||||
// Obtain pixel value through shifting
|
/* Obtain pixel value through shifting */
|
||||||
TPixelRGBA32 p = ((TPixelRGBA32) (((float) 0xFF) * c.m_a)) << 24;
|
TPixelRGBA32 p = ((TPixelRGBA32) (((float) 0xFF) * c.m_a)) << 24;
|
||||||
p |= ((TPixelRGBA32) (((float) 0xFF) * c.m_b)) << 16;
|
p |= ((TPixelRGBA32) (((float) 0xFF) * c.m_b)) << 16;
|
||||||
p |= ((TPixelRGBA32) (((float) 0xFF) * c.m_g)) << 8;
|
p |= ((TPixelRGBA32) (((float) 0xFF) * c.m_g)) << 8;
|
||||||
p |= ((TPixelRGBA32) (((float) 0xFF) * c.m_r));
|
p |= ((TPixelRGBA32) (((float) 0xFF) * c.m_r));
|
||||||
return p;
|
return p;
|
||||||
#else
|
#else
|
||||||
// Obtain pixel value through byte indexing
|
/* Obtain pixel value through byte indexing */
|
||||||
TPixelRGBA32 pixel;
|
TPixelRGBA32 pixel;
|
||||||
GEN_TUns8* bytes = (GEN_TUns8*)&pixel;
|
GEN_TUns8* bytes = (GEN_TUns8*)&pixel;
|
||||||
bytes[bi_r] = (GEN_TUns8)(((float) 0xFF) * c.m_r);
|
bytes[bi_r] = (GEN_TUns8)(((float) 0xFF) * c.m_r);
|
||||||
@@ -199,13 +199,13 @@ inline IMG_PixmapRGBA32::TPixelRGBA32 IMG_PixmapRGBA32::getPixelValue(const IMG_
|
|||||||
inline void IMG_PixmapRGBA32::getColor(TPixelRGBA32 p, IMG_ColorRGBA& c) const
|
inline void IMG_PixmapRGBA32::getColor(TPixelRGBA32 p, IMG_ColorRGBA& c) const
|
||||||
{
|
{
|
||||||
#if 0
|
#if 0
|
||||||
// Obtain color value through shifting
|
/* Obtain color value through shifting */
|
||||||
c.m_a = ((float) ((p >> 24) & 0x00FF)) / ((float) 0xFF);
|
c.m_a = ((float) ((p >> 24) & 0x00FF)) / ((float) 0xFF);
|
||||||
c.m_b = ((float) ((p >> 16) & 0x00FF)) / ((float) 0xFF);
|
c.m_b = ((float) ((p >> 16) & 0x00FF)) / ((float) 0xFF);
|
||||||
c.m_g = ((float) ((p >> 8) & 0x00FF)) / ((float) 0xFF);
|
c.m_g = ((float) ((p >> 8) & 0x00FF)) / ((float) 0xFF);
|
||||||
c.m_r = ((float) ( p & 0x00FF)) / ((float) 0xFF);
|
c.m_r = ((float) ( p & 0x00FF)) / ((float) 0xFF);
|
||||||
#else
|
#else
|
||||||
// Obtain color value through byte indexing
|
/* Obtain color value through byte indexing */
|
||||||
GEN_TUns8* bytes = (GEN_TUns8*)&p;
|
GEN_TUns8* bytes = (GEN_TUns8*)&p;
|
||||||
c.m_r = ((float)bytes[bi_r]) / ((float) 0xFF);
|
c.m_r = ((float)bytes[bi_r]) / ((float) 0xFF);
|
||||||
c.m_g = ((float)bytes[bi_g]) / ((float) 0xFF);
|
c.m_g = ((float)bytes[bi_g]) / ((float) 0xFF);
|
||||||
@@ -214,4 +214,4 @@ inline void IMG_PixmapRGBA32::getColor(TPixelRGBA32 p, IMG_ColorRGBA& c) const
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // _H_IMG_PixmapRGBA32
|
#endif /* _H_IMG_PixmapRGBA32 */
|
||||||
|
@@ -128,7 +128,7 @@ inline IMG_ColorRGB::IMG_ColorRGB(const IMG_ColorRGBA& c)
|
|||||||
|
|
||||||
inline void IMG_ColorRGBA::blendColor(const IMG_ColorRGBA& c)
|
inline void IMG_ColorRGBA::blendColor(const IMG_ColorRGBA& c)
|
||||||
{
|
{
|
||||||
float r1 = 1 - c.m_a; // The reverse of alpha
|
float r1 = 1 - c.m_a; /* The reverse of alpha */
|
||||||
#if IMG_REVERSED_ALPHA
|
#if IMG_REVERSED_ALPHA
|
||||||
m_r = c.m_a * m_r + r1 * c.m_r;
|
m_r = c.m_a * m_r + r1 * c.m_r;
|
||||||
m_g = c.m_a * m_g + r1 * c.m_g;
|
m_g = c.m_a * m_g + r1 * c.m_g;
|
||||||
@@ -141,4 +141,4 @@ inline void IMG_ColorRGBA::blendColor(const IMG_ColorRGBA& c)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif // _H_IMG_Color
|
#endif /* _H_IMG_Color */
|
||||||
|
@@ -114,4 +114,4 @@ public:
|
|||||||
operator T*() { return m_p; }
|
operator T*() { return m_p; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _H_IMG_MemPtr
|
#endif /* _H_IMG_MemPtr */
|
||||||
|
@@ -39,7 +39,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "../extern/IMG_PixmapRGBA32.h"
|
#include "IMG_PixmapRGBA32.h"
|
||||||
|
|
||||||
IMG_PixmapRGBA32::IMG_PixmapRGBA32(GEN_TUns32 width, GEN_TUns32 height)
|
IMG_PixmapRGBA32::IMG_PixmapRGBA32(GEN_TUns32 width, GEN_TUns32 height)
|
||||||
: IMG_Pixmap(), m_pixels(width * height)
|
: IMG_Pixmap(), m_pixels(width * height)
|
||||||
@@ -67,14 +67,15 @@ IMG_PixmapRGBA32::IMG_PixmapRGBA32(void* image, GEN_TUns32 width, GEN_TUns32 hei
|
|||||||
|
|
||||||
void IMG_PixmapRGBA32::fillRect(const GEN_Rect& r, const IMG_ColorRGB& c)
|
void IMG_PixmapRGBA32::fillRect(const GEN_Rect& r, const IMG_ColorRGB& c)
|
||||||
{
|
{
|
||||||
GEN_Rect t_bnds (0, 0, m_width, m_height); // Bounds of this pixmap
|
GEN_Rect t_bnds (0, 0, m_width, m_height); /* Bounds of this pixmap */
|
||||||
GEN_Rect r_bnds (r); // Area to set
|
GEN_Rect r_bnds (r); /* Area to set */
|
||||||
|
|
||||||
// Determine visibility
|
/* Determine visibility */
|
||||||
GEN_TVisibility v = t_bnds.getVisibility(r_bnds);
|
GEN_TVisibility v = t_bnds.getVisibility(r_bnds);
|
||||||
if (v == GEN_kNotVisible) return;
|
if (v == GEN_kNotVisible) return;
|
||||||
if (v == GEN_kPartiallyVisible) {
|
if (v == GEN_kPartiallyVisible) {
|
||||||
// Clip the destination rectangle to the bounds of this pixmap
|
/* Clip the destination rectangle to the bounds of this pixmap
|
||||||
|
*/
|
||||||
t_bnds.clip(r_bnds);
|
t_bnds.clip(r_bnds);
|
||||||
if (r_bnds.isEmpty()) {
|
if (r_bnds.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
@@ -82,35 +83,35 @@ void IMG_PixmapRGBA32::fillRect(const GEN_Rect& r, const IMG_ColorRGB& c)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
// Set new pixels using shifting
|
/* Set new pixels using shifting */
|
||||||
// Prepare the pixel value to set
|
/* Prepare the pixel value to set */
|
||||||
IMG_ColorRGBA ca (c);
|
IMG_ColorRGBA ca (c);
|
||||||
TPixelRGBA32 pv = getPixelValue(c);
|
TPixelRGBA32 pv = getPixelValue(c);
|
||||||
// Mask off the alpha bits
|
/* Mask off the alpha bits */
|
||||||
pv &= 0x00FFFFFF; //0xFFFFFF00;
|
pv &= 0x00FFFFFF; /* 0xFFFFFF00; */
|
||||||
|
|
||||||
// Set the pixels in the destination rectangle
|
/* Set the pixels in the destination rectangle */
|
||||||
for (GEN_TInt32 y = r.m_t; y < r.m_b; y++) {
|
for (GEN_TInt32 y = r.m_t; y < r.m_b; y++) {
|
||||||
// Park pixel pointer at the start pixels
|
/* Park pixel pointer at the start pixels */
|
||||||
TPixelPtr desPtr = getPixelPtr(r_bnds.m_l, y);
|
TPixelPtr desPtr = getPixelPtr(r_bnds.m_l, y);
|
||||||
for (GEN_TInt32 x = r.m_l; x < r.m_r; x++) {
|
for (GEN_TInt32 x = r.m_l; x < r.m_r; x++) {
|
||||||
// Set the new pixel value (retain current alpha)
|
/* Set the new pixel value (retain current alpha) */
|
||||||
*(desPtr++) = pv | ((*desPtr) & 0xFF000000); //0x000000FF);
|
*(desPtr++) = pv | ((*desPtr) & 0xFF000000); /*0x000000FF); */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
// Set new values using byte indexing
|
/* Set new values using byte indexing */
|
||||||
//IMG_ColorRGBA ca (c);
|
/*IMG_ColorRGBA ca (c); */
|
||||||
TPixelRGBA32 src = getPixelValue(c);
|
TPixelRGBA32 src = getPixelValue(c);
|
||||||
TPixelPtr desPtr;
|
TPixelPtr desPtr;
|
||||||
GEN_TUns8* srcBytes = (GEN_TUns8*) &src;
|
GEN_TUns8* srcBytes = (GEN_TUns8*) &src;
|
||||||
|
|
||||||
// Set the pixels in the destination rectangle
|
/* Set the pixels in the destination rectangle */
|
||||||
for (GEN_TInt32 y = r.m_t; y < r.m_b; y++) {
|
for (GEN_TInt32 y = r.m_t; y < r.m_b; y++) {
|
||||||
// Park pixel pointer at the start pixels
|
/* Park pixel pointer at the start pixels */
|
||||||
desPtr = getPixelPtr(r_bnds.m_l, y);
|
desPtr = getPixelPtr(r_bnds.m_l, y);
|
||||||
for (GEN_TInt32 x = r.m_l; x < r.m_r; x++) {
|
for (GEN_TInt32 x = r.m_l; x < r.m_r; x++) {
|
||||||
// Set the new pixel value (retain current alpha)
|
/* Set the new pixel value (retain current alpha) */
|
||||||
((GEN_TUns8*)desPtr)[bi_r] = srcBytes[bi_r];
|
((GEN_TUns8*)desPtr)[bi_r] = srcBytes[bi_r];
|
||||||
((GEN_TUns8*)desPtr)[bi_g] = srcBytes[bi_g];
|
((GEN_TUns8*)desPtr)[bi_g] = srcBytes[bi_g];
|
||||||
((GEN_TUns8*)desPtr)[bi_b] = srcBytes[bi_b];
|
((GEN_TUns8*)desPtr)[bi_b] = srcBytes[bi_b];
|
||||||
@@ -123,24 +124,25 @@ void IMG_PixmapRGBA32::fillRect(const GEN_Rect& r, const IMG_ColorRGB& c)
|
|||||||
|
|
||||||
void IMG_PixmapRGBA32::fillRect(const GEN_Rect& r, const IMG_ColorRGBA& c)
|
void IMG_PixmapRGBA32::fillRect(const GEN_Rect& r, const IMG_ColorRGBA& c)
|
||||||
{
|
{
|
||||||
GEN_Rect t_bnds (0, 0, m_width, m_height); // Bounds of this pixmap
|
GEN_Rect t_bnds (0, 0, m_width, m_height); /* Bounds of this pixmap */
|
||||||
GEN_Rect r_bnds (r); // Area to set
|
GEN_Rect r_bnds (r); /* Area to set */
|
||||||
|
|
||||||
// Determine visibility
|
/* Determine visibility */
|
||||||
GEN_TVisibility v = t_bnds.getVisibility(r_bnds);
|
GEN_TVisibility v = t_bnds.getVisibility(r_bnds);
|
||||||
if (v == GEN_kNotVisible) return;
|
if (v == GEN_kNotVisible) return;
|
||||||
if (v == GEN_kPartiallyVisible) {
|
if (v == GEN_kPartiallyVisible) {
|
||||||
// Clip the destination rectangle to the bounds of this pixmap
|
/* Clip the destination rectangle to the bounds of this pixmap
|
||||||
|
*/
|
||||||
t_bnds.clip(r_bnds);
|
t_bnds.clip(r_bnds);
|
||||||
if (r_bnds.isEmpty()) {
|
if (r_bnds.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the pixels in the destination rectangle
|
/* Set the pixels in the destination rectangle */
|
||||||
TPixelRGBA32 pixel = getPixelValue(c);
|
TPixelRGBA32 pixel = getPixelValue(c);
|
||||||
for (GEN_TInt32 y = r.m_t; y < r.m_b; y++) {
|
for (GEN_TInt32 y = r.m_t; y < r.m_b; y++) {
|
||||||
// Park pixel pointer at the start pixels
|
/* Park pixel pointer at the start pixels */
|
||||||
TPixelPtr desPtr = getPixelPtr(r_bnds.m_l, y);
|
TPixelPtr desPtr = getPixelPtr(r_bnds.m_l, y);
|
||||||
for (GEN_TInt32 x = r.m_l; x < r.m_r; x++) {
|
for (GEN_TInt32 x = r.m_l; x < r.m_r; x++) {
|
||||||
*(desPtr++) = pixel;
|
*(desPtr++) = pixel;
|
||||||
@@ -151,21 +153,22 @@ void IMG_PixmapRGBA32::fillRect(const GEN_Rect& r, const IMG_ColorRGBA& c)
|
|||||||
|
|
||||||
void IMG_PixmapRGBA32::setPixmap(const IMG_PixmapRGBA32& src, const GEN_Rect& srcBnds, const GEN_Rect& destBnds)
|
void IMG_PixmapRGBA32::setPixmap(const IMG_PixmapRGBA32& src, const GEN_Rect& srcBnds, const GEN_Rect& destBnds)
|
||||||
{
|
{
|
||||||
GEN_Rect i_bnds (srcBnds); // Bounds of input pixmap
|
GEN_Rect i_bnds (srcBnds); /* Bounds of input pixmap */
|
||||||
GEN_Rect t_bnds (0, 0, m_width, m_height); // Bounds of this pixmap
|
GEN_Rect t_bnds (0, 0, m_width, m_height); /* Bounds of this pixmap */
|
||||||
GEN_Rect p_bnds (destBnds); // Bounds of the paste area
|
GEN_Rect p_bnds (destBnds); /* Bounds of the paste area */
|
||||||
|
|
||||||
// The next check could be removed if the caller is made responsible for handing us non-empty rectangles
|
/* The next check could be removed if the caller is made
|
||||||
|
responsible for handing us non-empty rectangles */
|
||||||
if (i_bnds.isEmpty()) {
|
if (i_bnds.isEmpty()) {
|
||||||
// Nothing to do
|
/* Nothing to do */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine visibility of the paste area
|
/* Determine visibility of the paste area */
|
||||||
GEN_TVisibility v = t_bnds.getVisibility(p_bnds);
|
GEN_TVisibility v = t_bnds.getVisibility(p_bnds);
|
||||||
if (v == GEN_kNotVisible) return;
|
if (v == GEN_kNotVisible) return;
|
||||||
if (v == GEN_kPartiallyVisible) {
|
if (v == GEN_kPartiallyVisible) {
|
||||||
// Clipping is needed
|
/* Clipping is needed */
|
||||||
if (p_bnds.m_l < 0) {
|
if (p_bnds.m_l < 0) {
|
||||||
i_bnds.m_l += -p_bnds.m_l;
|
i_bnds.m_l += -p_bnds.m_l;
|
||||||
p_bnds.m_l = 0;
|
p_bnds.m_l = 0;
|
||||||
@@ -186,12 +189,12 @@ void IMG_PixmapRGBA32::setPixmap(const IMG_PixmapRGBA32& src, const GEN_Rect& sr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterate through the rows
|
/* Iterate through the rows */
|
||||||
for (GEN_TInt32 r = 0; r < p_bnds.getHeight(); r++) {
|
for (GEN_TInt32 r = 0; r < p_bnds.getHeight(); r++) {
|
||||||
// Park pixel pointers at the start pixels
|
/* Park pixel pointers at the start pixels */
|
||||||
TPixelPtr srcPtr = src.getPixelPtr(i_bnds.m_l, i_bnds.m_t + r);
|
TPixelPtr srcPtr = src.getPixelPtr(i_bnds.m_l, i_bnds.m_t + r);
|
||||||
TPixelPtr desPtr = getPixelPtr(p_bnds.m_l, p_bnds.m_t + r);
|
TPixelPtr desPtr = getPixelPtr(p_bnds.m_l, p_bnds.m_t + r);
|
||||||
// Iterate through the columns
|
/* Iterate through the columns */
|
||||||
for (int c = 0; c < p_bnds.getWidth(); c++) {
|
for (int c = 0; c < p_bnds.getWidth(); c++) {
|
||||||
*(desPtr++) = *(srcPtr++);
|
*(desPtr++) = *(srcPtr++);
|
||||||
}
|
}
|
||||||
@@ -201,21 +204,22 @@ void IMG_PixmapRGBA32::setPixmap(const IMG_PixmapRGBA32& src, const GEN_Rect& sr
|
|||||||
|
|
||||||
void IMG_PixmapRGBA32::blendPixmap(const IMG_PixmapRGBA32& src, const GEN_Rect& srcBnds, const GEN_Rect& destBnds)
|
void IMG_PixmapRGBA32::blendPixmap(const IMG_PixmapRGBA32& src, const GEN_Rect& srcBnds, const GEN_Rect& destBnds)
|
||||||
{
|
{
|
||||||
GEN_Rect i_bnds (srcBnds); // Bounds of input pixmap
|
GEN_Rect i_bnds (srcBnds); /* Bounds of input pixmap */
|
||||||
GEN_Rect t_bnds (0, 0, m_width, m_height); // Bounds of this pixmap
|
GEN_Rect t_bnds (0, 0, m_width, m_height); /* Bounds of this pixmap */
|
||||||
GEN_Rect p_bnds (destBnds); // Bounds of the paste area
|
GEN_Rect p_bnds (destBnds); /* Bounds of the paste area */
|
||||||
|
|
||||||
// The next check could be removed if the caller is made responsible for handing us non-empty rectangles
|
/* The next check could be removed if the caller is made responsible
|
||||||
|
for handing us non-empty rectangles */
|
||||||
if (i_bnds.isEmpty()) {
|
if (i_bnds.isEmpty()) {
|
||||||
// Nothing to do
|
/* Nothing to do */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine visibility of the paste area
|
/* Determine visibility of the paste area */
|
||||||
GEN_TVisibility v = t_bnds.getVisibility(p_bnds);
|
GEN_TVisibility v = t_bnds.getVisibility(p_bnds);
|
||||||
if (v == GEN_kNotVisible) return;
|
if (v == GEN_kNotVisible) return;
|
||||||
if (v == GEN_kPartiallyVisible) {
|
if (v == GEN_kPartiallyVisible) {
|
||||||
// Clipping is needed
|
/* Clipping is needed */
|
||||||
if (p_bnds.m_l < 0) {
|
if (p_bnds.m_l < 0) {
|
||||||
i_bnds.m_l += -p_bnds.m_l;
|
i_bnds.m_l += -p_bnds.m_l;
|
||||||
p_bnds.m_l = 0;
|
p_bnds.m_l = 0;
|
||||||
@@ -239,19 +243,19 @@ void IMG_PixmapRGBA32::blendPixmap(const IMG_PixmapRGBA32& src, const GEN_Rect&
|
|||||||
IMG_ColorRGBA srcColor;
|
IMG_ColorRGBA srcColor;
|
||||||
IMG_ColorRGBA desColor;
|
IMG_ColorRGBA desColor;
|
||||||
|
|
||||||
// Iterate through the rows
|
/* Iterate through the rows */
|
||||||
for (int r = 0; r < p_bnds.getHeight(); r++) {
|
for (int r = 0; r < p_bnds.getHeight(); r++) {
|
||||||
// Park pixel pointers at the start pixels
|
/* Park pixel pointers at the start pixels */
|
||||||
TPixelPtr srcPtr = src.getPixelPtr(i_bnds.m_l, i_bnds.m_t + r);
|
TPixelPtr srcPtr = src.getPixelPtr(i_bnds.m_l, i_bnds.m_t + r);
|
||||||
TPixelPtr desPtr = getPixelPtr(p_bnds.m_l, p_bnds.m_t + r);
|
TPixelPtr desPtr = getPixelPtr(p_bnds.m_l, p_bnds.m_t + r);
|
||||||
// Iterate through the columns
|
/* Iterate through the columns */
|
||||||
for (int c = 0; c < p_bnds.getWidth(); c++) {
|
for (int c = 0; c < p_bnds.getWidth(); c++) {
|
||||||
// Retrieve colors from source and destination pixmaps
|
/* Retrieve colors from source and destination pixmaps*/
|
||||||
getColor(*srcPtr, srcColor);
|
getColor(*srcPtr, srcColor);
|
||||||
getColor(*desPtr, desColor);
|
getColor(*desPtr, desColor);
|
||||||
// Blend the colors
|
/* Blend the colors */
|
||||||
desColor.blendColor(srcColor);
|
desColor.blendColor(srcColor);
|
||||||
// Write color back to destination pixmap
|
/* Write color back to destination pixmap */
|
||||||
*desPtr = getPixelValue(desColor);
|
*desPtr = getPixelValue(desColor);
|
||||||
srcPtr++;
|
srcPtr++;
|
||||||
desPtr++;
|
desPtr++;
|
||||||
|
@@ -29,7 +29,7 @@
|
|||||||
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// ex:ts=4
|
/* ex:ts=4 */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* $Id$
|
* $Id$
|
||||||
@@ -41,7 +41,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "key.h" // external interface
|
#include "blenkey.h" /* external interface */
|
||||||
#include "key_internal.h"
|
#include "key_internal.h"
|
||||||
|
|
||||||
char *Hexify(byte *in, unsigned int length) {
|
char *Hexify(byte *in, unsigned int length) {
|
||||||
@@ -69,7 +69,7 @@ byte *DeHexify(char *in) {
|
|||||||
*outp = (byte) hexedbyte;
|
*outp = (byte) hexedbyte;
|
||||||
outp++;
|
outp++;
|
||||||
}
|
}
|
||||||
// printf("\nlen=%d, string=[%s]\n", len, Hexify(out, len/2));
|
/* printf("\nlen=%d, string=[%s]\n", len, Hexify(out, len/2)); */
|
||||||
return (out);
|
return (out);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,52 +77,52 @@ int from_hex(char c) {
|
|||||||
return (c<'A') ? (c-'0') : (c-'A'+10);
|
return (c<'A') ? (c-'0') : (c-'A'+10);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5 ReadHex helper functions ------------------------------------------
|
/* 5 ReadHex helper functions ------------------------------------------
|
||||||
// read one Hex byte (two characters) and skip newlines if necessary
|
read one Hex byte (two characters) and skip newlines if necessary */
|
||||||
byte ReadHexByteFp(FILE *fh, int *newlinetracker) {
|
byte ReadHexByteFp(FILE *fh, int *newlinetracker) {
|
||||||
unsigned char a;
|
unsigned char a;
|
||||||
unsigned char a1, a2;
|
unsigned char a1, a2;
|
||||||
// read 2 bytes hexcode of ascii data type
|
/* read 2 bytes hexcode of ascii data type */
|
||||||
fread(&a1, 1, 1, fh);
|
fread(&a1, 1, 1, fh);
|
||||||
fread(&a2, 1, 1, fh);
|
fread(&a2, 1, 1, fh);
|
||||||
a = 16 * (from_hex(a1)) + (from_hex(a2));
|
a = 16 * (from_hex(a1)) + (from_hex(a2));
|
||||||
//printf("Char[%d] = %02X\n", *newlinetracker, a);
|
/*printf("Char[%d] = %02X\n", *newlinetracker, a); */
|
||||||
*newlinetracker += 2;
|
*newlinetracker += 2;
|
||||||
// skip the newlines
|
/* skip the newlines */
|
||||||
if (*newlinetracker == 72) {
|
if (*newlinetracker == 72) {
|
||||||
fseek(fh, 1, SEEK_CUR);
|
fseek(fh, 1, SEEK_CUR);
|
||||||
*newlinetracker = 0;
|
*newlinetracker = 0;
|
||||||
//printf("LastChar = %02X\n", a);
|
/*printf("LastChar = %02X\n", a); */
|
||||||
}
|
}
|
||||||
return((byte) a);
|
return((byte) a);
|
||||||
}
|
}
|
||||||
byte ReadHexByteCp(char **from) {
|
byte ReadHexByteCp(char **from) {
|
||||||
int a;
|
int a;
|
||||||
// read 2 bytes hexcode of ascii data type
|
/* read 2 bytes hexcode of ascii data type */
|
||||||
sscanf(*from, "%2x", &a);
|
sscanf(*from, "%2x", &a);
|
||||||
//printf("Char = %02X\n", a);
|
/*printf("Char = %02X\n", a); */
|
||||||
*from += 2;
|
*from += 2;
|
||||||
return((byte) a);
|
return((byte) a);
|
||||||
}
|
}
|
||||||
// Generic hex2int
|
/* Generic hex2int */
|
||||||
int HexToInt(int a) {
|
int HexToInt(int a) {
|
||||||
if (a == 0x20) // space, count as 0 ;-)
|
if (a == 0x20) /* space, count as 0 ;-) */
|
||||||
return 0;
|
return 0;
|
||||||
else
|
else
|
||||||
return(a - '0');
|
return(a - '0');
|
||||||
}
|
}
|
||||||
// Note: this is only to be used for the header type
|
/* Note: this is only to be used for the header type */
|
||||||
int HexToIntFp(FILE *fh, int *newlinetracker) {
|
int HexToIntFp(FILE *fh, int *newlinetracker) {
|
||||||
byte a = ReadHexByteFp(fh, newlinetracker);
|
byte a = ReadHexByteFp(fh, newlinetracker);
|
||||||
if (DEBUG) printf("%02X = %d\n", a, a); // note: no HexToInt here
|
if (DEBUG) printf("%02X = %d\n", a, a); /* note: no HexToInt here */
|
||||||
return(a);
|
return(a);
|
||||||
}
|
}
|
||||||
int HexToIntCp(char **from) {
|
int HexToIntCp(char **from) {
|
||||||
byte a = ReadHexByteCp(from);
|
byte a = ReadHexByteCp(from);
|
||||||
if (DEBUG) printf("%02X = %d\n", a, a); // note: no HexToInt here
|
if (DEBUG) printf("%02X = %d\n", a, a); /* note: no HexToInt here */
|
||||||
return(a);
|
return(a);
|
||||||
}
|
}
|
||||||
// Note: this is only to be used for the header length
|
/* Note: this is only to be used for the header length */
|
||||||
int Hex5ToInt(byte a, byte b, byte c, byte d, byte e) {
|
int Hex5ToInt(byte a, byte b, byte c, byte d, byte e) {
|
||||||
return(HexToInt((int) a) * 10000 +
|
return(HexToInt((int) a) * 10000 +
|
||||||
HexToInt((int) b) * 1000 +
|
HexToInt((int) b) * 1000 +
|
||||||
@@ -130,7 +130,7 @@ int Hex5ToInt(byte a, byte b, byte c, byte d, byte e) {
|
|||||||
HexToInt((int) d) * 10 +
|
HexToInt((int) d) * 10 +
|
||||||
HexToInt((int) e));
|
HexToInt((int) e));
|
||||||
}
|
}
|
||||||
// Note: this is only to be used for the header length
|
/* Note: this is only to be used for the header length */
|
||||||
int Hex5ToIntFp(FILE *fh, int *newlinetracker) {
|
int Hex5ToIntFp(FILE *fh, int *newlinetracker) {
|
||||||
byte a = ReadHexByteFp(fh, newlinetracker),
|
byte a = ReadHexByteFp(fh, newlinetracker),
|
||||||
b = ReadHexByteFp(fh, newlinetracker),
|
b = ReadHexByteFp(fh, newlinetracker),
|
||||||
@@ -151,27 +151,27 @@ int Hex5ToIntCp(char **from) {
|
|||||||
Hex5ToInt(a, b, c, d, e));
|
Hex5ToInt(a, b, c, d, e));
|
||||||
return(Hex5ToInt(a, b, c, d, e));
|
return(Hex5ToInt(a, b, c, d, e));
|
||||||
}
|
}
|
||||||
// ---------------------------------------------------------------------
|
/* --------------------------------------------------------------------- */
|
||||||
|
|
||||||
// return the biggest
|
/* return the biggest */
|
||||||
byte checkfunc0(byte a, byte b) {
|
byte checkfunc0(byte a, byte b) {
|
||||||
if (a > b) return a;
|
if (a > b) return a;
|
||||||
else return b;
|
else return b;
|
||||||
}
|
}
|
||||||
// return |a-b|
|
/* return |a-b| */
|
||||||
byte checkfunc1(byte a, byte b) {
|
byte checkfunc1(byte a, byte b) {
|
||||||
if (a > b) return a - b;
|
if (a > b) return a - b;
|
||||||
else return b - a;
|
else return b - a;
|
||||||
}
|
}
|
||||||
// return the sum mod 256
|
/* return the sum mod 256 */
|
||||||
byte checkfunc2(byte a, byte b) {
|
byte checkfunc2(byte a, byte b) {
|
||||||
return ((a + b) % 256);
|
return ((a + b) % 256);
|
||||||
}
|
}
|
||||||
// return the multiplication mod 256
|
/* return the multiplication mod 256 */
|
||||||
byte checkfunc3(byte a, byte b) {
|
byte checkfunc3(byte a, byte b) {
|
||||||
return ((a * b) % 256);
|
return ((a * b) % 256);
|
||||||
}
|
}
|
||||||
// return a/b or 0
|
/* return a/b or 0 */
|
||||||
byte checkfunc4(byte a, byte b) {
|
byte checkfunc4(byte a, byte b) {
|
||||||
if (b != 0) return (a / b);
|
if (b != 0) return (a / b);
|
||||||
else return 0;
|
else return 0;
|
||||||
@@ -187,8 +187,8 @@ char *scan_ascii(FILE *fh, UserStruct *User) {
|
|||||||
int lines = 0;
|
int lines = 0;
|
||||||
int oldftell;
|
int oldftell;
|
||||||
|
|
||||||
// NOTE: fscanf is notorious for its buffer overflows. This must be
|
/* NOTE: fscanf is notorious for its buffer overflows. This must be
|
||||||
// fixed some day, consider this a proof-of-concept version.
|
fixed some day, consider this a proof-of-concept version. */
|
||||||
|
|
||||||
fscanf(fh, "%1000[^\n]", string);
|
fscanf(fh, "%1000[^\n]", string);
|
||||||
sscanf(string, "%*s %s %s %lu %d %d %d",
|
sscanf(string, "%*s %s %s %lu %d %d %d",
|
||||||
@@ -205,13 +205,13 @@ char *scan_ascii(FILE *fh, UserStruct *User) {
|
|||||||
User->email, User->shopid, User->reldate, User->keytype,
|
User->email, User->shopid, User->reldate, User->keytype,
|
||||||
User->keylevel);
|
User->keylevel);
|
||||||
|
|
||||||
// read /n/n
|
/* read /n/n
|
||||||
|
check if we're reading dow newlines...
|
||||||
// check if we're reading dow newlines...
|
*/
|
||||||
oldftell = ftell(fh);
|
oldftell = ftell(fh);
|
||||||
getc(fh);
|
getc(fh);
|
||||||
if ((ftell(fh) - oldftell) == 2) {
|
if ((ftell(fh) - oldftell) == 2) {
|
||||||
// yes !
|
/* yes ! */
|
||||||
dosnewlines = 1;
|
dosnewlines = 1;
|
||||||
}
|
}
|
||||||
getc(fh);
|
getc(fh);
|
||||||
@@ -223,25 +223,27 @@ char *scan_ascii(FILE *fh, UserStruct *User) {
|
|||||||
|
|
||||||
getc(fh);
|
getc(fh);
|
||||||
|
|
||||||
// 4 lines read uptil now...
|
/* 4 lines read uptil now... */
|
||||||
lines = 4;
|
lines = 4;
|
||||||
|
|
||||||
while (getc(fh) != EOF) {
|
while (getc(fh) != EOF) {
|
||||||
fscanf(fh, "%1000[^\n]", string);
|
fscanf(fh, "%1000[^\n]", string);
|
||||||
lines++;
|
lines++;
|
||||||
// if (DEBUG) printf("%s\n", string);
|
/* if (DEBUG) printf("%s\n", string); */
|
||||||
if (strcmp(string, BLENKEYSEPERATOR) == 0) {
|
if (strcmp(string, BLENKEYSEPERATOR) == 0) {
|
||||||
getc(fh);
|
getc(fh);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// fh now points at the start of the datablock
|
/* fh now points at the start of the datablock */
|
||||||
ascii_size = ftell(fh);
|
ascii_size = ftell(fh);
|
||||||
|
|
||||||
if (dosnewlines) {
|
if (dosnewlines) {
|
||||||
// if we were reading on dos
|
/* if we were reading on dos
|
||||||
// ftell will also count the ^M 's in the file; substract them
|
ftell will also count the ^M 's in the file;
|
||||||
|
substract them
|
||||||
|
*/
|
||||||
ascii_size -= lines;
|
ascii_size -= lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -253,7 +255,7 @@ char *scan_ascii(FILE *fh, UserStruct *User) {
|
|||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
printf("asciiblock is %ld bytes long:\n[%s]\n", ascii_size, ascii_data);
|
printf("asciiblock is %ld bytes long:\n[%s]\n", ascii_size, ascii_data);
|
||||||
|
|
||||||
// calculate the hash checksum
|
/* calculate the hash checksum */
|
||||||
RIPEMD160(ascii_data, ascii_size, md);
|
RIPEMD160(ascii_data, ascii_size, md);
|
||||||
free(ascii_data);
|
free(ascii_data);
|
||||||
mdhex = Hexify(md, RIPEMD160_DIGEST_LENGTH);
|
mdhex = Hexify(md, RIPEMD160_DIGEST_LENGTH);
|
||||||
@@ -269,7 +271,7 @@ char *ReadHexCryptedData(FILE *fh, int *newlinetracker) {
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (DataType != 1) {
|
if (DataType != 1) {
|
||||||
// printf("Error: unexpected datatype for HexCryptedData\n");
|
/* printf("Error: unexpected datatype for HexCryptedData\n"); */
|
||||||
free(HexCryptedData);
|
free(HexCryptedData);
|
||||||
HexCryptedData = 0;
|
HexCryptedData = 0;
|
||||||
} else {
|
} else {
|
||||||
@@ -288,7 +290,7 @@ char *ReadHexCryptedKey(FILE *fh, int *newlinetracker) {
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (DataType != 2) {
|
if (DataType != 2) {
|
||||||
// printf("Error: unexpected datatype for HexCryptedKey\n");
|
/* printf("Error: unexpected datatype for HexCryptedKey\n"); */
|
||||||
free(HexCryptedKey);
|
free(HexCryptedKey);
|
||||||
HexCryptedKey = 0;
|
HexCryptedKey = 0;
|
||||||
} else {
|
} else {
|
||||||
@@ -300,7 +302,7 @@ char *ReadHexCryptedKey(FILE *fh, int *newlinetracker) {
|
|||||||
return(HexCryptedKey);
|
return(HexCryptedKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: CHANGE THIS INTO A KEY OF OUR OWN
|
/* NOTE: CHANGE THIS INTO A KEY OF OUR OWN */
|
||||||
void LoadRSApubKey(RSA *Pub) {
|
void LoadRSApubKey(RSA *Pub) {
|
||||||
static unsigned char n[] =
|
static unsigned char n[] =
|
||||||
"\xD1\x12\x0C\x6A\x34\x0A\xCF\x4C\x6B\x34\xA9\x3C\xDD\x1A\x2A\x68"
|
"\xD1\x12\x0C\x6A\x34\x0A\xCF\x4C\x6B\x34\xA9\x3C\xDD\x1A\x2A\x68"
|
||||||
@@ -330,10 +332,10 @@ byte *RSADecryptKey(char *HexCryptedKey) {
|
|||||||
int CryptedKeyLen = strlen(HexCryptedKey)/2;
|
int CryptedKeyLen = strlen(HexCryptedKey)/2;
|
||||||
RSA *Pub = NULL;
|
RSA *Pub = NULL;
|
||||||
|
|
||||||
// Load RSA public key
|
/* Load RSA public key */
|
||||||
Pub = RSA_new();
|
Pub = RSA_new();
|
||||||
if (Pub == NULL) {
|
if (Pub == NULL) {
|
||||||
// printf("Error in RSA_new\n");
|
/* printf("Error in RSA_new\n"); */
|
||||||
} else {
|
} else {
|
||||||
LoadRSApubKey(Pub);
|
LoadRSApubKey(Pub);
|
||||||
|
|
||||||
@@ -376,7 +378,7 @@ char *get_from_datablock(char **DataPtr, char *TypeString) {
|
|||||||
char *HexString = NULL;
|
char *HexString = NULL;
|
||||||
|
|
||||||
if (atoi(TypeString) != tstringtype) {
|
if (atoi(TypeString) != tstringtype) {
|
||||||
// printf("Unexpected type %d, expected %s\n", tstringtype, TypeString);
|
/* printf("Unexpected type %d, expected %s\n", tstringtype, TypeString); */
|
||||||
} else {
|
} else {
|
||||||
HexString = malloc((tstringsize+1) * sizeof(char));
|
HexString = malloc((tstringsize+1) * sizeof(char));
|
||||||
|
|
||||||
@@ -393,7 +395,7 @@ int ReadKeyFile(char *filename, UserStruct *User,
|
|||||||
FILE *rawkeyfile;
|
FILE *rawkeyfile;
|
||||||
char *HexAsciiHash = NULL, *HexCryptedData = NULL, *HexCryptedKey =
|
char *HexAsciiHash = NULL, *HexCryptedData = NULL, *HexCryptedKey =
|
||||||
NULL;
|
NULL;
|
||||||
int newlinetracker = 0; // line position, counts from 0-71
|
int newlinetracker = 0; /* line position, counts from 0-71 */
|
||||||
byte *CryptKey = NULL;
|
byte *CryptKey = NULL;
|
||||||
char *KeyDataString = NULL;
|
char *KeyDataString = NULL;
|
||||||
char *KeyDataPtr = NULL;
|
char *KeyDataPtr = NULL;
|
||||||
@@ -402,29 +404,29 @@ int ReadKeyFile(char *filename, UserStruct *User,
|
|||||||
int ret_val = 1;
|
int ret_val = 1;
|
||||||
|
|
||||||
if ((rawkeyfile = fopen(filename, "rb")) == NULL) {
|
if ((rawkeyfile = fopen(filename, "rb")) == NULL) {
|
||||||
// printf("error, cannot read %s\n", filename);
|
/* printf("error, cannot read %s\n", filename); */
|
||||||
} else {
|
} else {
|
||||||
// Scan and interpret the ASCII part
|
/* Scan and interpret the ASCII part */
|
||||||
HexAsciiHash = scan_ascii(rawkeyfile, User);
|
HexAsciiHash = scan_ascii(rawkeyfile, User);
|
||||||
if (DEBUG) printf("\nHexHash: %s\n", HexAsciiHash);
|
if (DEBUG) printf("\nHexHash: %s\n", HexAsciiHash);
|
||||||
|
|
||||||
// Read the HexCryptedData
|
/* Read the HexCryptedData */
|
||||||
HexCryptedData = ReadHexCryptedData(rawkeyfile, &newlinetracker);
|
HexCryptedData = ReadHexCryptedData(rawkeyfile, &newlinetracker);
|
||||||
if (DEBUG) printf("\nHexCryptedData: %s\n", HexCryptedData);
|
if (DEBUG) printf("\nHexCryptedData: %s\n", HexCryptedData);
|
||||||
|
|
||||||
// Read the HexCryptedKey
|
/* Read the HexCryptedKey */
|
||||||
HexCryptedKey = ReadHexCryptedKey(rawkeyfile, &newlinetracker);
|
HexCryptedKey = ReadHexCryptedKey(rawkeyfile, &newlinetracker);
|
||||||
if (DEBUG) printf("\nHexCryptedKey: %s\n", HexCryptedKey);
|
if (DEBUG) printf("\nHexCryptedKey: %s\n", HexCryptedKey);
|
||||||
|
|
||||||
// close keyfile
|
/* close keyfile */
|
||||||
fclose(rawkeyfile);
|
fclose(rawkeyfile);
|
||||||
|
|
||||||
if (HexAsciiHash && HexCryptedKey && HexCryptedData) {
|
if (HexAsciiHash && HexCryptedKey && HexCryptedData) {
|
||||||
// Decrypt HexCryptedKey
|
/* Decrypt HexCryptedKey */
|
||||||
CryptKey = RSADecryptKey(HexCryptedKey);
|
CryptKey = RSADecryptKey(HexCryptedKey);
|
||||||
|
|
||||||
if (CryptKey) {
|
if (CryptKey) {
|
||||||
// Decrypt HexCryptedData
|
/* Decrypt HexCryptedData */
|
||||||
KeyDataString = DeCryptDatablock(CryptKey, 16, HexCryptedData);
|
KeyDataString = DeCryptDatablock(CryptKey, 16, HexCryptedData);
|
||||||
free(CryptKey);
|
free(CryptKey);
|
||||||
CryptKey = NULL;
|
CryptKey = NULL;
|
||||||
@@ -432,7 +434,7 @@ int ReadKeyFile(char *filename, UserStruct *User,
|
|||||||
if (KeyDataString) {
|
if (KeyDataString) {
|
||||||
if (DEBUG) printf("\nKeyDataString: %s\n", KeyDataString);
|
if (DEBUG) printf("\nKeyDataString: %s\n", KeyDataString);
|
||||||
|
|
||||||
// Extract data from KeyDataString
|
/* Extract data from KeyDataString */
|
||||||
KeyDataPtr = KeyDataString;
|
KeyDataPtr = KeyDataString;
|
||||||
mdhex = get_from_datablock(&KeyDataPtr, "01");
|
mdhex = get_from_datablock(&KeyDataPtr, "01");
|
||||||
*Priv = get_from_datablock(&KeyDataPtr, "02");
|
*Priv = get_from_datablock(&KeyDataPtr, "02");
|
||||||
@@ -445,15 +447,16 @@ int ReadKeyFile(char *filename, UserStruct *User,
|
|||||||
|
|
||||||
*Python = get_from_datablock(&KeyDataPtr, "05");
|
*Python = get_from_datablock(&KeyDataPtr, "05");
|
||||||
|
|
||||||
// Check ascii hash
|
/* Check ascii hash */
|
||||||
if (strcmp(mdhex, HexAsciiHash) != 0) {
|
if (strcmp(mdhex, HexAsciiHash) != 0) {
|
||||||
// printf("Ascii part checksums do not match !\n");
|
/* printf("Ascii part checksums do not match !\n");
|
||||||
// printf("found: %s\n", mdhex);
|
printf("found: %s\n", mdhex);
|
||||||
// printf("check: %s\n", HexAsciiHash);
|
printf("check: %s\n", HexAsciiHash);
|
||||||
|
*/
|
||||||
ret_val = 2;
|
ret_val = 2;
|
||||||
} else {
|
} else {
|
||||||
if (DEBUG) printf("\nThe ascii part checksum matches\n");
|
if (DEBUG) printf("\nThe ascii part checksum matches\n");
|
||||||
// everything ok !
|
/* everything ok ! */
|
||||||
ret_val = 0;
|
ret_val = 0;
|
||||||
}
|
}
|
||||||
free(mdhex);
|
free(mdhex);
|
||||||
@@ -466,7 +469,7 @@ int ReadKeyFile(char *filename, UserStruct *User,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// cleanup
|
/* cleanup */
|
||||||
|
|
||||||
if (HexAsciiHash) {
|
if (HexAsciiHash) {
|
||||||
free(HexAsciiHash);
|
free(HexAsciiHash);
|
||||||
|
@@ -50,9 +50,9 @@ typedef struct UserStructType {
|
|||||||
char email[100];
|
char email[100];
|
||||||
char shopid[100];
|
char shopid[100];
|
||||||
unsigned long reldate;
|
unsigned long reldate;
|
||||||
int keytype; // 1 = Individual, 2 = Corporate, 3 = Unlimited
|
int keytype; /* 1 = Individual, 2 = Corporate, 3 = Unlimited */
|
||||||
int keylevel; // key disclosure level, starts at 1
|
int keylevel; /* key disclosure level, starts at 1 */
|
||||||
int keyformat; // if we change the keyformat, up BLENKEYFORMAT
|
int keyformat; /* if we change the keyformat, up BLENKEYFORMAT */
|
||||||
} UserStruct;
|
} UserStruct;
|
||||||
|
|
||||||
char *Hexify(byte *in, unsigned int length);
|
char *Hexify(byte *in, unsigned int length);
|
||||||
@@ -64,8 +64,8 @@ byte checkfunc2(byte a, byte b);
|
|||||||
byte checkfunc3(byte a, byte b);
|
byte checkfunc3(byte a, byte b);
|
||||||
byte checkfunc4(byte a, byte b);
|
byte checkfunc4(byte a, byte b);
|
||||||
|
|
||||||
// the byte size of the checksum datablock
|
/* the byte size of the checksum datablock
|
||||||
// #define MAXBYTEDATABLOCK 1000
|
#define MAXBYTEDATABLOCK 1000 */
|
||||||
|
|
||||||
#define BLENKEYMAGIC "0ce0ba52"
|
#define BLENKEYMAGIC "0ce0ba52"
|
||||||
#define BLENKEYSEPERATOR "---+++---"
|
#define BLENKEYSEPERATOR "---+++---"
|
||||||
|
@@ -29,7 +29,7 @@
|
|||||||
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// ex:ts=4
|
/* ex:ts=4 */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* $Id$
|
* $Id$
|
||||||
@@ -43,7 +43,7 @@
|
|||||||
#include "openssl/rc4.h"
|
#include "openssl/rc4.h"
|
||||||
#include "openssl/err.h"
|
#include "openssl/err.h"
|
||||||
|
|
||||||
#include "mt19937int.h" // Mersenne Twister (under artistic license)
|
#include "mt19937int.h" /* Mersenne Twister (under artistic license) */
|
||||||
|
|
||||||
#define MAXASCIIBLOCK 1000
|
#define MAXASCIIBLOCK 1000
|
||||||
#define MAXBYTEDATABLOCK 1000
|
#define MAXBYTEDATABLOCK 1000
|
||||||
@@ -54,7 +54,7 @@
|
|||||||
#define DEBUG 1
|
#define DEBUG 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// keyloader and keymaker internal prototypes
|
/* keyloader and keymaker internal prototypes */
|
||||||
int from_hex(char c);
|
int from_hex(char c);
|
||||||
byte ReadHexByteFp(FILE *fh, int *newlinetracker);
|
byte ReadHexByteFp(FILE *fh, int *newlinetracker);
|
||||||
byte ReadHexByteCp(char **from);
|
byte ReadHexByteCp(char **from);
|
||||||
@@ -66,7 +66,7 @@ int Hex5ToIntFp(FILE *fh, int *newlinetracker);
|
|||||||
int Hex5ToIntCp(char **from);
|
int Hex5ToIntCp(char **from);
|
||||||
int main(int argc, char **argv);
|
int main(int argc, char **argv);
|
||||||
|
|
||||||
// keyloader only internal prototypes
|
/* keyloader only internal prototypes */
|
||||||
char *scan_ascii(FILE *fh, UserStruct *User);
|
char *scan_ascii(FILE *fh, UserStruct *User);
|
||||||
char *ReadHexCryptedData(FILE *fh, int *newlinetracker);
|
char *ReadHexCryptedData(FILE *fh, int *newlinetracker);
|
||||||
char *ReadHexCryptedKey(FILE *fh, int *newlinetracker);
|
char *ReadHexCryptedKey(FILE *fh, int *newlinetracker);
|
||||||
@@ -76,7 +76,7 @@ char *DeCryptDatablock(byte *CryptKey, int keylen, char *HexCryptedData);
|
|||||||
char *get_from_datablock(char **DataPtr, char *TypeString);
|
char *get_from_datablock(char **DataPtr, char *TypeString);
|
||||||
int Check_All_Byte_Calculus_Data(char *KeyBytePtr);
|
int Check_All_Byte_Calculus_Data(char *KeyBytePtr);
|
||||||
|
|
||||||
// keymaker only internal prototypes
|
/* keymaker only internal prototypes */
|
||||||
void usage(void);
|
void usage(void);
|
||||||
char *Create_Ascii_Part(int argc, char **argv);
|
char *Create_Ascii_Part(int argc, char **argv);
|
||||||
void Create_User_RSA_Keys(unsigned int keylength,
|
void Create_User_RSA_Keys(unsigned int keylength,
|
||||||
|
@@ -29,7 +29,7 @@
|
|||||||
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// ex:ts=4
|
/* ex:ts=4 */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* $Id$
|
* $Id$
|
||||||
@@ -41,8 +41,8 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "key_pyc.h" // the Python byte code
|
#include "key_pyc.h" /* the Python byte code */
|
||||||
#include "key.h" // the external interface
|
#include "blenkey.h" /* the external interface */
|
||||||
#include "key_internal.h"
|
#include "key_internal.h"
|
||||||
|
|
||||||
#define TESTReadKeyFile 1
|
#define TESTReadKeyFile 1
|
||||||
@@ -50,7 +50,7 @@
|
|||||||
int Check_All_Byte_Calculus_Data(char *KeyBytePtr) {
|
int Check_All_Byte_Calculus_Data(char *KeyBytePtr) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
// create some unique number arrays
|
/* create some unique number arrays */
|
||||||
int NoRealRandomArray[MAXBYTEDATABLOCK];
|
int NoRealRandomArray[MAXBYTEDATABLOCK];
|
||||||
|
|
||||||
typedef byte (*funcpoin)(byte, byte);
|
typedef byte (*funcpoin)(byte, byte);
|
||||||
@@ -59,20 +59,20 @@ int Check_All_Byte_Calculus_Data(char *KeyBytePtr) {
|
|||||||
|
|
||||||
byte *KeyByteData = DeHexify(KeyBytePtr);
|
byte *KeyByteData = DeHexify(KeyBytePtr);
|
||||||
|
|
||||||
// first create a fixed seed random number generator
|
/* first create a fixed seed random number generator */
|
||||||
sgenrand(666); // seed it fixed
|
sgenrand(666); /* seed it fixed */
|
||||||
|
|
||||||
// initialize arrays with unique numbers
|
/* initialize arrays with unique numbers */
|
||||||
for (i=0; i<MAXBYTEDATABLOCK; i++) {
|
for (i=0; i<MAXBYTEDATABLOCK; i++) {
|
||||||
NoRealRandomArray[i] = i;
|
NoRealRandomArray[i] = i;
|
||||||
}
|
}
|
||||||
// then stir the unique number lists
|
/* then stir the unique number lists */
|
||||||
for (i=0; i<MAXBYTEDATABLOCK; i++) {
|
for (i=0; i<MAXBYTEDATABLOCK; i++) {
|
||||||
unsigned long randswap = genrand();
|
unsigned long randswap = genrand();
|
||||||
int swap1 = (int) (randswap % MAXBYTEDATABLOCK);
|
int swap1 = (int) (randswap % MAXBYTEDATABLOCK);
|
||||||
int swap2 = (int) ((randswap>>16) % MAXBYTEDATABLOCK);
|
int swap2 = (int) ((randswap>>16) % MAXBYTEDATABLOCK);
|
||||||
int store = NoRealRandomArray[swap1];
|
int store = NoRealRandomArray[swap1];
|
||||||
//printf("%lu %d %d\n", randswap, swap1, swap2);
|
/* printf("%lu %d %d\n", randswap, swap1, swap2); */
|
||||||
NoRealRandomArray[swap1] = NoRealRandomArray[swap2];
|
NoRealRandomArray[swap1] = NoRealRandomArray[swap2];
|
||||||
NoRealRandomArray[swap2] = store;
|
NoRealRandomArray[swap2] = store;
|
||||||
}
|
}
|
||||||
@@ -84,7 +84,7 @@ int Check_All_Byte_Calculus_Data(char *KeyBytePtr) {
|
|||||||
printf("\n\n");
|
printf("\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// check our byte calculus functions on the random data
|
/* check our byte calculus functions on the random data */
|
||||||
for (i=0; i<(MAXBYTEDATABLOCK-3); i+=3) {
|
for (i=0; i<(MAXBYTEDATABLOCK-3); i+=3) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
char *Pcheckfunc[] = {"max", " - ", " + ", " * ", " / "};
|
char *Pcheckfunc[] = {"max", " - ", " + ", " * ", " / "};
|
||||||
@@ -114,7 +114,7 @@ int Check_All_Byte_Calculus_Data(char *KeyBytePtr) {
|
|||||||
void pub_priv_test(char *HexPriv, char *HexPub)
|
void pub_priv_test(char *HexPriv, char *HexPub)
|
||||||
{
|
{
|
||||||
RSA *rsa = NULL;
|
RSA *rsa = NULL;
|
||||||
// static unsigned char rsa_e[] = "\x11";
|
/* static unsigned char rsa_e[] = "\x11"; */
|
||||||
static unsigned char rsa_e[] = "\x01\x00\x01";
|
static unsigned char rsa_e[] = "\x01\x00\x01";
|
||||||
byte cryptKey[16];
|
byte cryptKey[16];
|
||||||
byte *cryptedKey;
|
byte *cryptedKey;
|
||||||
@@ -185,15 +185,15 @@ int main(int argc, char **argv) {
|
|||||||
printf("\nReadKeyFile OK\n");
|
printf("\nReadKeyFile OK\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// just print the rsaPrivString and rsaPubString
|
/* just print the rsaPrivString and rsaPubString */
|
||||||
if (DEBUG) printf("\nrsaPrivString: %s\n", HexPriv);
|
if (DEBUG) printf("\nrsaPrivString: %s\n", HexPriv);
|
||||||
if (DEBUG) printf("\nrsaPubString: %s\n", HexPub);
|
if (DEBUG) printf("\nrsaPubString: %s\n", HexPub);
|
||||||
|
|
||||||
// try to private encrypt-public decrypt something
|
/* try to private encrypt-public decrypt something */
|
||||||
if (DEBUG) pub_priv_test(HexPriv, HexPub);
|
if (DEBUG) pub_priv_test(HexPriv, HexPub);
|
||||||
|
|
||||||
// check all the Byte checksums
|
/* check all the Byte checksums
|
||||||
// rehexify it for our Check_All_Byte_Calculus_Data function ...
|
rehexify it for our Check_All_Byte_Calculus_Data function ... */
|
||||||
HexByte = Hexify(Byte, 1000);
|
HexByte = Hexify(Byte, 1000);
|
||||||
if (Check_All_Byte_Calculus_Data(HexByte) != 0) {
|
if (Check_All_Byte_Calculus_Data(HexByte) != 0) {
|
||||||
printf("\nByte_Calculus_Data checksums do not match !\n");
|
printf("\nByte_Calculus_Data checksums do not match !\n");
|
||||||
@@ -202,7 +202,7 @@ int main(int argc, char **argv) {
|
|||||||
if (DEBUG) printf("\nThe Byte Calculus Data checksums match\n");
|
if (DEBUG) printf("\nThe Byte Calculus Data checksums match\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check the KeyPythonPtr
|
/* Check the KeyPythonPtr */
|
||||||
PythonLength = strlen(HexPython)/2;
|
PythonLength = strlen(HexPython)/2;
|
||||||
PythonData = DeHexify(HexPython);
|
PythonData = DeHexify(HexPython);
|
||||||
if (memcmp(PythonData, g_keycode, PythonLength) != 0) {
|
if (memcmp(PythonData, g_keycode, PythonLength) != 0) {
|
||||||
@@ -219,7 +219,7 @@ int main(int argc, char **argv) {
|
|||||||
FILE *rawkeyfile;
|
FILE *rawkeyfile;
|
||||||
char *AsciiHash;
|
char *AsciiHash;
|
||||||
char *HexCryptedData, *HexCryptedKey;
|
char *HexCryptedData, *HexCryptedKey;
|
||||||
int newlinetracker = 0; // line position, counts from 0-71
|
int newlinetracker = 0; /* line position, counts from 0-71 */
|
||||||
byte *CryptKey;
|
byte *CryptKey;
|
||||||
char *KeyDataString;
|
char *KeyDataString;
|
||||||
char *KeyDataPtr;
|
char *KeyDataPtr;
|
||||||
@@ -237,38 +237,38 @@ int main(int argc, char **argv) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// open keyfile for reading
|
/* open keyfile for reading */
|
||||||
if ((rawkeyfile = fopen(argv[1], "r")) == NULL) {
|
if ((rawkeyfile = fopen(argv[1], "r")) == NULL) {
|
||||||
printf("error, cannot read %s\n", argv[1]);
|
printf("error, cannot read %s\n", argv[1]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scan and interpret the ASCII part
|
/* Scan and interpret the ASCII part */
|
||||||
AsciiHash = scan_ascii(rawkeyfile, &User);
|
AsciiHash = scan_ascii(rawkeyfile, &User);
|
||||||
if (DEBUG) printf("\nHexHash: %s\n", AsciiHash);
|
if (DEBUG) printf("\nHexHash: %s\n", AsciiHash);
|
||||||
|
|
||||||
// Read the HexCryptedData
|
/* Read the HexCryptedData */
|
||||||
HexCryptedData = ReadHexCryptedData(rawkeyfile, &newlinetracker);
|
HexCryptedData = ReadHexCryptedData(rawkeyfile, &newlinetracker);
|
||||||
if (DEBUG) printf("\nHexCryptedData: %s\n", HexCryptedData);
|
if (DEBUG) printf("\nHexCryptedData: %s\n", HexCryptedData);
|
||||||
|
|
||||||
// Read the HexCryptedKey
|
/* Read the HexCryptedKey */
|
||||||
HexCryptedKey = ReadHexCryptedKey(rawkeyfile, &newlinetracker);
|
HexCryptedKey = ReadHexCryptedKey(rawkeyfile, &newlinetracker);
|
||||||
if (DEBUG) printf("\nHexCryptedKey: %s\n", HexCryptedKey);
|
if (DEBUG) printf("\nHexCryptedKey: %s\n", HexCryptedKey);
|
||||||
|
|
||||||
// close keyfile
|
/* close keyfile */
|
||||||
fclose(rawkeyfile);
|
fclose(rawkeyfile);
|
||||||
|
|
||||||
// Decrypt HexCryptedKey
|
/* Decrypt HexCryptedKey */
|
||||||
CryptKey = RSADecryptKey(HexCryptedKey);
|
CryptKey = RSADecryptKey(HexCryptedKey);
|
||||||
|
|
||||||
// Decrypt HexCryptedData
|
/* Decrypt HexCryptedData */
|
||||||
KeyDataString = DeCryptDatablock(CryptKey, 16, HexCryptedData);
|
KeyDataString = DeCryptDatablock(CryptKey, 16, HexCryptedData);
|
||||||
free(CryptKey);
|
free(CryptKey);
|
||||||
free(HexCryptedData);
|
free(HexCryptedData);
|
||||||
free(HexCryptedKey);
|
free(HexCryptedKey);
|
||||||
if (DEBUG) printf("\nKeyDataString: %s\n", KeyDataString);
|
if (DEBUG) printf("\nKeyDataString: %s\n", KeyDataString);
|
||||||
|
|
||||||
// Extract data from KeyDataString
|
/* Extract data from KeyDataString */
|
||||||
KeyDataPtr = KeyDataString;
|
KeyDataPtr = KeyDataString;
|
||||||
|
|
||||||
mdhex = get_from_datablock(&KeyDataPtr, "01");
|
mdhex = get_from_datablock(&KeyDataPtr, "01");
|
||||||
@@ -278,7 +278,7 @@ int main(int argc, char **argv) {
|
|||||||
KeyPythonPtr = get_from_datablock(&KeyDataPtr, "05");
|
KeyPythonPtr = get_from_datablock(&KeyDataPtr, "05");
|
||||||
free(KeyDataString);
|
free(KeyDataString);
|
||||||
|
|
||||||
// Check ascii hash
|
/* Check ascii hash */
|
||||||
if (strcmp(mdhex, AsciiHash) != 0) {
|
if (strcmp(mdhex, AsciiHash) != 0) {
|
||||||
printf("Ascii part checksums do not match !\n");
|
printf("Ascii part checksums do not match !\n");
|
||||||
printf("found: %s\n", mdhex);
|
printf("found: %s\n", mdhex);
|
||||||
@@ -288,11 +288,11 @@ int main(int argc, char **argv) {
|
|||||||
if (DEBUG) printf("\nThe ascii part checksum matches\n");
|
if (DEBUG) printf("\nThe ascii part checksum matches\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// just print the rsaPrivString and rsaPubString
|
/* just print the rsaPrivString and rsaPubString */
|
||||||
if (DEBUG) printf("\nrsaPrivString: %s\n", rsaPrivString);
|
if (DEBUG) printf("\nrsaPrivString: %s\n", rsaPrivString);
|
||||||
if (DEBUG) printf("\nrsaPubString: %s\n", rsaPubString);
|
if (DEBUG) printf("\nrsaPubString: %s\n", rsaPubString);
|
||||||
|
|
||||||
// check all the Byte checksums
|
/* check all the Byte checksums */
|
||||||
if (Check_All_Byte_Calculus_Data(KeyBytePtr) != 0) {
|
if (Check_All_Byte_Calculus_Data(KeyBytePtr) != 0) {
|
||||||
printf("Byte_Calculus_Data checksums do not match !\n");
|
printf("Byte_Calculus_Data checksums do not match !\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
@@ -300,7 +300,7 @@ int main(int argc, char **argv) {
|
|||||||
if (DEBUG) printf("\nThe Byte Calculus Data checksums match\n");
|
if (DEBUG) printf("\nThe Byte Calculus Data checksums match\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check the KeyPythonPtr
|
/* Check the KeyPythonPtr */
|
||||||
PythonLength = strlen(KeyPythonPtr)/2;
|
PythonLength = strlen(KeyPythonPtr)/2;
|
||||||
PythonData = DeHexify(KeyPythonPtr);
|
PythonData = DeHexify(KeyPythonPtr);
|
||||||
if (memcmp(PythonData, g_keycode, PythonLength) != 0) {
|
if (memcmp(PythonData, g_keycode, PythonLength) != 0) {
|
||||||
|
@@ -29,7 +29,7 @@
|
|||||||
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// ex:ts=4
|
/* ex:ts=4 */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* $Id$
|
* $Id$
|
||||||
@@ -37,9 +37,9 @@
|
|||||||
* Mersenne Twister prototypes
|
* Mersenne Twister prototypes
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// external:
|
/* external: */
|
||||||
void sgenrand(signed long seed);
|
void sgenrand(signed long seed);
|
||||||
unsigned long genrand(void);
|
unsigned long genrand(void);
|
||||||
|
|
||||||
// internal:
|
/* internal: */
|
||||||
void lsgenrand(unsigned long *seed_array);
|
void lsgenrand(unsigned long *seed_array);
|
||||||
|
Reference in New Issue
Block a user