Windows portability fixes.
authormsheby <msheby@cinecert.com>
Mon, 29 Oct 2007 21:24:32 +0000 (21:24 +0000)
committermsheby <>
Mon, 29 Oct 2007 21:24:32 +0000 (21:24 +0000)
README
src/AS_DCP.h
src/AS_DCP_AES.cpp
src/AS_DCP_JP2K.cpp
src/AS_DCP_TimedText.cpp
src/AS_DCP_internal.h
src/KM_error.h
src/KM_util.cpp
src/h__Reader.cpp

diff --git a/README b/README
index 2885d7820cd5a2c78fbb4a2cedac6a8c0b027c1d..5d863bc8d38bcc23ae1967e5e0fa4720ed469eb8 100755 (executable)
--- a/README
+++ b/README
@@ -116,6 +116,19 @@ utilities all respond to -h.
 
 
 Change History
+2007.10.29 - Bug fixes v.1.2.17
+ o Changed Result_t implementation to use int instead of long, which
+   was causing trouble on some 64 bit platforms.
+ o Fixed EKLV HMAC. Broke backward compatibility with older Interop
+   files. To validate these files use asdcplib-1.1.14. This should
+   not cause too much trouble since files with broken and non-broken
+   HMAC have been in the wild for years without trouble.
+ o Fixed HMAC sequence numbering in encrypted stereoscopic files.
+ o Finished stereoscopic test targets in the makefile.
+ o Fixed the win32 build, now expects VS2005 compiler by default,
+   use WITH_VC6=1 top get VS6 flags.
+
+
 2007.10.22 - Timed Text, Stereoscopic Picture and Bug fixes v.1.2.16
  o Significant API changes have been made. Please read all entries
    in this changelog to be sure you understand the changes. Also
index 5f75521c2d211fb1bf9d4f13b92a14e20844b50c..1cefa98de534e893579e85a7baddb5ac09d16a37 100755 (executable)
@@ -155,7 +155,7 @@ namespace ASDCP {
   // 1.0.1. If changes were also required in AS_DCP.h, the new version would be 1.1.1.
   const ui32_t VERSION_MAJOR = 1;
   const ui32_t VERSION_APIMINOR = 2;
-  const ui32_t VERSION_IMPMINOR = 16;
+  const ui32_t VERSION_IMPMINOR = 17;
   const char* Version();
 
   // UUIDs are passed around as strings of UUIDlen bytes
index cd3e41bbee1b12881c9796080790ecb0368ab0e3..dbaa3d541d383c4c7e43a514a8a15c75e7f5840e 100755 (executable)
@@ -241,11 +241,19 @@ ASDCP::AESDecContext::DecryptBlock(const byte_t* ct_buf, byte_t* pt_buf, ui32_t
 
 static const ui32_t B_len = 64; // rfc 2104, Sec. 2
 
-static byte_t ipad[KeyLen] = { 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
-                              0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36 };
+static byte_t ipad[B_len] = {
+  0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
+  0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
+  0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
+  0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36
+};
 
-static byte_t opad[KeyLen] = { 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c,
-                              0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c };
+static byte_t opad[B_len] = {
+  0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c,
+  0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c,
+  0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c,
+  0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c
+};
 
 class HMACContext::h__HMACContext
 {
@@ -255,7 +263,6 @@ class HMACContext::h__HMACContext
 
 public:
   byte_t     m_SHAValue[HMAC_SIZE];
-  LabelSet_t m_SetType;
   bool       m_Final;
 
   h__HMACContext() : m_Final(false) {}
@@ -267,7 +274,6 @@ public:
     byte_t rng_buf[SHA_DIGEST_LENGTH*2];
     Kumu::Gen_FIPS_186_Value(key, KeyLen, rng_buf, SHA_DIGEST_LENGTH*2);
     memcpy(m_key, rng_buf+SHA_DIGEST_LENGTH, KeyLen);
-    m_SetType = LS_MXF_SMPTE;
     Reset();
   }
 
@@ -285,7 +291,6 @@ public:
     SHA1_Update(&SHA, key_nonce, KeyLen);
     SHA1_Final(sha_buf, &SHA);
     memcpy(m_key, sha_buf, KeyLen);
-    m_SetType = LS_MXF_INTEROP;
     Reset();
   }
 
@@ -294,28 +299,19 @@ public:
   Reset()
   {
     byte_t xor_buf[B_len];
+    memset(xor_buf, 0, B_len);
+    memcpy(xor_buf, m_key, KeyLen);
+
     memset(m_SHAValue, 0, HMAC_SIZE);
     m_Final = false;
     SHA1_Init(&m_SHA);
 
     // H(K XOR opad, H(K XOR ipad, text))
     //                 ^^^^^^^^^^
-    ui32_t i = 0;
-
-    for ( ; i < KeyLen; i++ )
-      xor_buf[i] = m_key[i] ^ ipad[i];
-
-    if ( m_SetType == LS_MXF_SMPTE )
-      {
-       for ( ; i < B_len; i++ )
-         xor_buf[i] = 0 ^ ipad[0];
-
-       SHA1_Update(&m_SHA, xor_buf, B_len);
-      }
-    else
-      {
-       SHA1_Update(&m_SHA, xor_buf, KeyLen);
-      }
+    for ( ui32_t i = 0; i < B_len; i++ )
+      xor_buf[i] ^= ipad[i];
+
+    SHA1_Update(&m_SHA, xor_buf, B_len);
   }
 
   //
@@ -331,34 +327,29 @@ public:
   void
   Finalize()
   {
-    // H(K XOR opad, H(K XOR ipad, text))
-    // ^^^^^^^^^^^^^^^
-    SHA1_Final(m_SHAValue, &m_SHA);
-
     SHA_CTX SHA;
     SHA1_Init(&SHA);
 
     byte_t xor_buf[B_len];
-    ui32_t i = 0;
-
-    for ( ; i < KeyLen; i++ )
-      xor_buf[i] = m_key[i] ^ opad[i];
-    
-    if ( m_SetType == LS_MXF_SMPTE )
-      {
-       for ( ; i < B_len; i++ )
-         xor_buf[i] = 0 ^ opad[0];
-
-       SHA1_Update(&m_SHA, xor_buf, B_len);
-      }
-    else
-      {
-       SHA1_Update(&m_SHA, xor_buf, KeyLen);
-      }
-    
-    SHA1_Update(&SHA, xor_buf, KeyLen);
+    memset(xor_buf, 0, B_len);
+    memcpy(xor_buf, m_key, KeyLen);
+
+    SHA1_Init(&SHA);
+
+    // H(K XOR opad, H(K XOR ipad, text))
+    //   ^^^^^^^^^^
+    for ( ui32_t i = 0; i < B_len; i++ )
+      xor_buf[i] ^= opad[i];
+
+    SHA1_Update(&SHA, xor_buf, B_len);
+
+    // H(K XOR opad, H(K XOR ipad, text))
+    //               ^
+    SHA1_Final(m_SHAValue, &m_SHA);
     SHA1_Update(&SHA, m_SHAValue, HMAC_SIZE);
 
+    // H(K XOR opad, H(K XOR ipad, text))
+    // ^
     SHA1_Final(m_SHAValue, &SHA);
     m_Final = true;
   }
index f5ce3354f9c19d2cc164beb1afa9232f1e8686d0..a1d9514f53da27d5f69205753dd481d1b43f094a 100755 (executable)
@@ -213,10 +213,12 @@ lh__Reader::OpenRead(const char* filename, EssenceType_t type)
 
   if( ASDCP_SUCCESS(result) )
     {
-      m_HeaderPart.GetMDObjectByType(OBJ_TYPE_ARGS(RGBAEssenceDescriptor),
-                                    (InterchangeObject**)&m_EssenceDescriptor);
-      m_HeaderPart.GetMDObjectByType(OBJ_TYPE_ARGS(JPEG2000PictureSubDescriptor),
-                                    (InterchangeObject**)&m_EssenceSubDescriptor);
+      InterchangeObject* tmp_iobj = 0;
+      m_HeaderPart.GetMDObjectByType(OBJ_TYPE_ARGS(RGBAEssenceDescriptor), &tmp_iobj);
+      m_EssenceDescriptor = static_cast<RGBAEssenceDescriptor*>(tmp_iobj);
+
+      m_HeaderPart.GetMDObjectByType(OBJ_TYPE_ARGS(JPEG2000PictureSubDescriptor), &tmp_iobj);
+      m_EssenceSubDescriptor = static_cast<JPEG2000PictureSubDescriptor*>(tmp_iobj);
 
       std::list<InterchangeObject*> ObjectList;
       m_HeaderPart.GetMDObjectsByType(OBJ_TYPE_ARGS(Track), ObjectList);
@@ -452,7 +454,11 @@ public:
       }
 
     if( ASDCP_SUCCESS(result) )
-      result = ReadEKLVPacket(FrameNum, FrameBuf, Dict::ul(MDD_JPEG2000Essence), Ctx, HMAC);
+      {
+       ui32_t SequenceNum = FrameNum * 2;
+       SequenceNum += ( phase == SP_RIGHT ) ? 2 : 1;
+       result = ReadEKLVPacket(FrameNum, SequenceNum, FrameBuf, Dict::ul(MDD_JPEG2000Essence), Ctx, HMAC);
+      }
 
     return result;
   }
@@ -718,9 +724,9 @@ lh__Writer::WriteFrame(const JP2K::FrameBuffer& FrameBuf, bool add_index,
       IndexTableSegment::IndexEntry Entry;
       Entry.StreamOffset = StreamOffset;
       m_FooterPart.PushIndexEntry(Entry);
-      m_FramesWritten++;
     }
 
+  m_FramesWritten++;
   return result;
 }
 
@@ -839,6 +845,8 @@ public:
     if ( m_NextPhase != SP_LEFT )
       return RESULT_SPHASE;
 
+    assert( m_FramesWritten % 2 == 0 );
+    m_FramesWritten /= 2;
     return lh__Writer::Finalize();
   }
 };
index bab3a6a1e616e338700fdad95ef282497f7d0d5e..7f89b1fa6235e60c389db3cdb80881f241005670 100644 (file)
@@ -98,8 +98,8 @@ typedef std::map<UUID, UUID> ResourceMap_t;
 
 class ASDCP::TimedText::MXFReader::h__Reader : public ASDCP::h__Reader
 {
-  TimedTextDescriptor*  m_EssenceDescriptor;
-  ResourceMap_t         m_ResourceMap;
+  DCTimedTextDescriptor* m_EssenceDescriptor;
+  ResourceMap_t          m_ResourceMap;
 
   ASDCP_NO_COPY_CONSTRUCT(h__Reader);
 
@@ -136,7 +136,9 @@ ASDCP::TimedText::MXFReader::h__Reader::MD_to_TimedText_TDesc(TimedText::TimedTe
 
   for ( ; sdi != TDescObj->SubDescriptors.end() && KM_SUCCESS(result); sdi++ )
     {
-      result = m_HeaderPart.GetMDObjectByID(*sdi, (InterchangeObject**)&DescObject);
+      InterchangeObject* tmp_iobj = 0;
+      result = m_HeaderPart.GetMDObjectByID(*sdi, &tmp_iobj);
+      DescObject = static_cast<DCTimedTextResourceDescriptor*>(tmp_iobj);
 
       if ( KM_SUCCESS(result) )
        {
@@ -174,9 +176,14 @@ ASDCP::TimedText::MXFReader::h__Reader::OpenRead(char const* filename)
   if( ASDCP_SUCCESS(result) )
     {
       if ( m_EssenceDescriptor == 0 )
-         m_HeaderPart.GetMDObjectByType(OBJ_TYPE_ARGS(DCTimedTextDescriptor), (InterchangeObject**)&m_EssenceDescriptor);
+       {
+         InterchangeObject* tmp_iobj = 0;
+         result = m_HeaderPart.GetMDObjectByType(OBJ_TYPE_ARGS(DCTimedTextDescriptor), &tmp_iobj);
+         m_EssenceDescriptor = static_cast<DCTimedTextDescriptor*>(tmp_iobj);
+       }
 
-      result = MD_to_TimedText_TDesc(m_TDesc);
+      if( ASDCP_SUCCESS(result) )
+       result = MD_to_TimedText_TDesc(m_TDesc);
     }
 
   if( ASDCP_SUCCESS(result) )
@@ -225,7 +232,9 @@ ASDCP::TimedText::MXFReader::h__Reader::ReadAncillaryResource(const byte_t* uuid
 
   DCTimedTextResourceDescriptor* DescObject = 0;
   // get the subdescriptor
-  Result_t result = m_HeaderPart.GetMDObjectByID((*ri).second, (InterchangeObject**)&DescObject);
+  InterchangeObject* tmp_iobj = 0;
+  Result_t result = m_HeaderPart.GetMDObjectByID((*ri).second, &tmp_iobj);
+  DescObject = static_cast<DCTimedTextResourceDescriptor*>(tmp_iobj);
 
   if ( KM_SUCCESS(result) )
     {
@@ -279,7 +288,7 @@ ASDCP::TimedText::MXFReader::h__Reader::ReadAncillaryResource(const byte_t* uuid
 
              // read the essence packet
              if( ASDCP_SUCCESS(result) )
-               result = ReadEKLVPacket(0, FrameBuf, Dict::ul(MDD_DCTimedTextDescriptor), Ctx, HMAC);
+               result = ReadEKLVPacket(0, 1, FrameBuf, Dict::ul(MDD_DCTimedTextDescriptor), Ctx, HMAC);
            }
        }
     }
index 143bccfc8dc5ac8c889b5e523930ebd6f8119a20..ed9eec7e92dbd9d0878ba1bd60a942475a3beca1 100755 (executable)
@@ -134,7 +134,7 @@ namespace ASDCP
                             const byte_t* EssenceUL, AESDecContext* Ctx, HMACContext* HMAC);
 
       // reads from current position
-      Result_t ReadEKLVPacket(ui32_t FrameNum, ASDCP::FrameBuffer& FrameBuf,
+      Result_t ReadEKLVPacket(ui32_t FrameNum, ui32_t SequenceNum, ASDCP::FrameBuffer& FrameBuf,
                              const byte_t* EssenceUL, AESDecContext* Ctx, HMACContext* HMAC);
       void     Close();
     };
index 2d3513a6c62d0483006ea2020311d662ca688be4..31d4f3ecf70a3a5964ffeb444e083d3a62f59c11 100755 (executable)
@@ -43,14 +43,14 @@ namespace Kumu
 
   class Result_t
     {
-      long value;
+      int value;
       const char* label;
       Result_t();
 
     public:
-      static const Result_t& Find(long);
+      static const Result_t& Find(int);
 
-      Result_t(long v, const char* l);
+      Result_t(int v, const char* l);
       ~Result_t();
 
       inline bool        operator==(const Result_t& rhs) const { return value == rhs.value; }
@@ -58,8 +58,8 @@ namespace Kumu
       inline bool        Success() const { return ( value >= 0 ); }
       inline bool        Failure() const { return ( value < 0 ); }
 
-      inline long        Value() const { return value; }
-      inline operator    long() const { return value; }
+      inline int         Value() const { return value; }
+      inline operator    int() const { return value; }
 
       inline const char* Label() const { return label; }
       inline operator    const char*() const { return label; }
index f9a88cd216683441133297d6d6ee937ef154530d..76b793901a5eb4e2efc0ad7d85169e5872c3d69d 100755 (executable)
@@ -45,7 +45,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 struct map_entry_t
 {
-  long            rcode;
+  int             rcode;
   Kumu::Result_t* result;
 };
 
@@ -56,7 +56,7 @@ static struct map_entry_t s_ResultMap[MapSize];
 
 //
 const Kumu::Result_t&
-Kumu::Result_t::Find(long v)
+Kumu::Result_t::Find(int v)
 {
   if ( v == 0 )
     return RESULT_OK;
@@ -72,7 +72,7 @@ Kumu::Result_t::Find(long v)
 }
 
 //
-Kumu::Result_t::Result_t(long v, const char* l) : value(v), label(l)
+Kumu::Result_t::Result_t(int v, const char* l) : value(v), label(l)
 {
   assert(l);
 
index 8035ac8c2eb4baea3840ea3c438ddb5bc36e393f..8d844f30490cca2d2c100ecba87d95b04c9d138a 100755 (executable)
@@ -194,14 +194,14 @@ ASDCP::h__Reader::ReadEKLVFrame(ui32_t FrameNum, ASDCP::FrameBuffer& FrameBuf,
     }
 
   if( ASDCP_SUCCESS(result) )
-    result = ReadEKLVPacket(FrameNum, FrameBuf, EssenceUL, Ctx, HMAC);
+    result = ReadEKLVPacket(FrameNum, FrameNum + 1, FrameBuf, EssenceUL, Ctx, HMAC);
 
   return result;
 }
 
 
 Result_t
-ASDCP::h__Reader::ReadEKLVPacket(ui32_t FrameNum, ASDCP::FrameBuffer& FrameBuf,
+ASDCP::h__Reader::ReadEKLVPacket(ui32_t FrameNum, ui32_t SequenceNum, ASDCP::FrameBuffer& FrameBuf,
                                 const byte_t* EssenceUL, AESDecContext* Ctx, HMACContext* HMAC)
 {
   KLReader Reader;
@@ -326,7 +326,7 @@ ASDCP::h__Reader::ReadEKLVPacket(ui32_t FrameNum, ASDCP::FrameBuffer& FrameBuf,
          if ( ASDCP_SUCCESS(result) && m_Info.UsesHMAC && HMAC )
            {
              IntegrityPack IntPack;
-             result = IntPack.TestValues(TmpWrapper, m_Info.AssetUUID, FrameNum + 1, HMAC);
+             result = IntPack.TestValues(TmpWrapper, m_Info.AssetUUID, SequenceNum, HMAC);
            }
        }
       else // return ciphertext to caller