1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
/*****************************************************************
|
| AP4 - ISMA E&A support
|
| Copyright 2002-2008 Axiomatic Systems, LLC
|
|
| This file is part of Bento4/AP4 (MP4 Atom Processing Library).
|
| Unless you have obtained Bento4 under a difference license,
| this version of Bento4 is Bento4|GPL.
| Bento4|GPL is free software; you can redistribute it and/or modify
| it under the terms of the GNU General Public License as published by
| the Free Software Foundation; either version 2, or (at your option)
| any later version.
|
| Bento4|GPL is distributed in the hope that it will be useful,
| but WITHOUT ANY WARRANTY; without even the implied warranty of
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
| GNU General Public License for more details.
|
| You should have received a copy of the GNU General Public License
| along with Bento4|GPL; see the file COPYING. If not, write to the
| Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
| 02111-1307, USA.
|
****************************************************************/
#ifndef _AP4_ISMACRYP_H_
#define _AP4_ISMACRYP_H_
/*----------------------------------------------------------------------
| includes
+---------------------------------------------------------------------*/
#include "Ap4Types.h"
#include "Ap4SampleEntry.h"
#include "Ap4Atom.h"
#include "Ap4AtomFactory.h"
#include "Ap4SampleDescription.h"
#include "Ap4Processor.h"
#include "Ap4Protection.h"
/*----------------------------------------------------------------------
| class references
+---------------------------------------------------------------------*/
class AP4_CtrStreamCipher;
class AP4_IsfmAtom;
/*----------------------------------------------------------------------
| constants
+---------------------------------------------------------------------*/
const AP4_UI32 AP4_PROTECTION_SCHEME_TYPE_IAEC = AP4_ATOM_TYPE('i','A','E','C');
/*----------------------------------------------------------------------
| AP4_IsmaCipher
+---------------------------------------------------------------------*/
class AP4_IsmaCipher : public AP4_SampleDecrypter
{
public:
// factory
static AP4_Result CreateSampleDecrypter(AP4_ProtectedSampleDescription* sample_description,
const AP4_UI08* key,
AP4_Size key_size,
AP4_BlockCipherFactory* block_cipher_factory,
AP4_IsmaCipher*& decrypter);
// constructor and destructor
AP4_IsmaCipher(AP4_BlockCipher* block_cipher,
const AP4_UI08* salt,
AP4_UI08 iv_length,
AP4_UI08 key_indicator_length,
bool selective_encryption);
~AP4_IsmaCipher();
AP4_Result EncryptSampleData(AP4_DataBuffer& data_in,
AP4_DataBuffer& data_out,
AP4_UI32 block_counter);
AP4_Result DecryptSampleData(AP4_UI32 pool_id, AP4_DataBuffer& data_in,
AP4_DataBuffer& data_out,
const AP4_UI08* iv = NULL);
AP4_Size GetDecryptedSampleSize(AP4_Sample& sample);
const AP4_UI08* GetSalt() { return m_Salt; }
AP4_CtrStreamCipher* GetCipher() { return m_Cipher; }
AP4_UI08 GetIvLength() { return m_IvLength; }
AP4_UI08 GetKeyIndicatorLength() { return m_KeyIndicatorLength; }
bool GetSelectiveEncryption(){ return m_SelectiveEncryption;}
private:
// members
AP4_CtrStreamCipher* m_Cipher;
AP4_UI08 m_Salt[8];
AP4_UI08 m_IvLength;
AP4_UI08 m_KeyIndicatorLength;
bool m_SelectiveEncryption;
};
/*----------------------------------------------------------------------
| AP4_IsmaTrackDecrypter
+---------------------------------------------------------------------*/
class AP4_IsmaTrackDecrypter : public AP4_Processor::TrackHandler {
public:
// construction
static AP4_Result Create(AP4_TrakAtom* trak,
AP4_TrexAtom* trex,
const AP4_UI08* key,
AP4_Size key_size,
AP4_ProtectedSampleDescription* sample_description,
AP4_SampleEntry* sample_entry,
AP4_BlockCipherFactory* block_cipher_factory,
AP4_IsmaTrackDecrypter*& decrypter);
virtual ~AP4_IsmaTrackDecrypter();
// methods
virtual AP4_Size GetProcessedSampleSize(AP4_Sample& sample);
virtual AP4_Result ProcessTrack();
virtual AP4_Result ProcessSample(AP4_DataBuffer& data_in,
AP4_DataBuffer& data_out);
private:
// constructor
AP4_IsmaTrackDecrypter(AP4_TrakAtom* trak,
AP4_TrexAtom* trex,
AP4_IsmaCipher* cipher,
AP4_SampleEntry* sample_entry,
AP4_UI32 original_format);
// members
AP4_IsmaCipher* m_Cipher;
AP4_SampleEntry* m_SampleEntry;
AP4_UI32 m_OriginalFormat;
};
/*----------------------------------------------------------------------
| AP4_IsmaEncryptingProcessor
+---------------------------------------------------------------------*/
class AP4_IsmaEncryptingProcessor : public AP4_Processor
{
public:
// constructors and destructor
AP4_IsmaEncryptingProcessor(const char* kms_uri,
AP4_BlockCipherFactory* block_cipher_factory = NULL);
// accessors
AP4_ProtectionKeyMap& GetKeyMap() { return m_KeyMap; }
// methods
virtual AP4_Processor::TrackHandler* CreateTrackHandler(AP4_TrakAtom* trak);
private:
// members
AP4_ProtectionKeyMap m_KeyMap;
AP4_String m_KmsUri;
AP4_BlockCipherFactory* m_BlockCipherFactory;
};
#endif // _AP4_ISMACRYP_H_
|