00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef _AP4_ISMACRYP_H_
00030 #define _AP4_ISMACRYP_H_
00031
00032
00033
00034
00035 #include "Ap4Types.h"
00036 #include "Ap4SampleEntry.h"
00037 #include "Ap4Atom.h"
00038 #include "Ap4AtomFactory.h"
00039 #include "Ap4SampleDescription.h"
00040 #include "Ap4Processor.h"
00041 #include "Ap4Protection.h"
00042
00043
00044
00045
00046 class AP4_CtrStreamCipher;
00047 class AP4_IsfmAtom;
00048
00049
00050
00051
00052 const AP4_UI32 AP4_PROTECTION_SCHEME_TYPE_IAEC = AP4_ATOM_TYPE('i','A','E','C');
00053
00054
00055
00056
00057 class AP4_IsmaCipher : public AP4_SampleDecrypter
00058 {
00059 public:
00060
00061 static AP4_Result CreateSampleDecrypter(AP4_ProtectedSampleDescription* sample_description,
00062 const AP4_UI08* key,
00063 AP4_Size key_size,
00064 AP4_BlockCipherFactory* block_cipher_factory,
00065 AP4_IsmaCipher** decrypter);
00066
00067
00068 AP4_IsmaCipher(AP4_BlockCipher* block_cipher,
00069 const AP4_UI08* salt,
00070 AP4_UI08 iv_length,
00071 AP4_UI08 key_indicator_length,
00072 bool selective_encryption);
00073 ~AP4_IsmaCipher();
00074 AP4_Result EncryptSampleData(AP4_DataBuffer& data_in,
00075 AP4_DataBuffer& data_out,
00076 AP4_UI32 offset);
00077 AP4_Result DecryptSampleData(AP4_DataBuffer& data_in,
00078 AP4_DataBuffer& data_out);
00079 AP4_CtrStreamCipher* GetCipher() { return m_Cipher; }
00080 AP4_UI08 GetIvLength() { return m_IvLength; }
00081 AP4_UI08 GetKeyIndicatorLength() { return m_KeyIndicatorLength; }
00082 bool GetSelectiveEncryption(){ return m_SelectiveEncryption;}
00083
00084 private:
00085
00086 AP4_CtrStreamCipher* m_Cipher;
00087 AP4_UI08 m_IvLength;
00088 AP4_UI08 m_KeyIndicatorLength;
00089 bool m_SelectiveEncryption;
00090 };
00091
00092
00093
00094
00095 class AP4_IsmaTrackDecrypter : public AP4_Processor::TrackHandler {
00096 public:
00097
00098 static AP4_Result Create(const AP4_UI08* key,
00099 AP4_Size key_size,
00100 AP4_ProtectedSampleDescription* sample_description,
00101 AP4_SampleEntry* sample_entry,
00102 AP4_BlockCipherFactory* block_cipher_factory,
00103 AP4_IsmaTrackDecrypter** decrypter);
00104
00105 virtual ~AP4_IsmaTrackDecrypter();
00106
00107
00108 virtual AP4_Size GetProcessedSampleSize(AP4_Sample& sample);
00109 virtual AP4_Result ProcessTrack();
00110 virtual AP4_Result ProcessSample(AP4_DataBuffer& data_in,
00111 AP4_DataBuffer& data_out);
00112
00113 private:
00114
00115 AP4_IsmaTrackDecrypter(AP4_IsmaCipher* cipher,
00116 AP4_SampleEntry* sample_entry,
00117 AP4_UI32 original_format);
00118
00119
00120 AP4_IsmaCipher* m_Cipher;
00121 AP4_SampleEntry* m_SampleEntry;
00122 AP4_UI32 m_OriginalFormat;
00123 };
00124
00125
00126
00127
00128 class AP4_IsmaEncryptingProcessor : public AP4_Processor
00129 {
00130 public:
00131
00132 AP4_IsmaEncryptingProcessor(const char* kms_uri,
00133 AP4_BlockCipherFactory* block_cipher_factory = NULL);
00134
00135
00136 AP4_ProtectionKeyMap& GetKeyMap() { return m_KeyMap; }
00137
00138
00139 virtual AP4_Processor::TrackHandler* CreateTrackHandler(AP4_TrakAtom* trak);
00140
00141 private:
00142
00143 AP4_ProtectionKeyMap m_KeyMap;
00144 AP4_String m_KmsUri;
00145 AP4_BlockCipherFactory* m_BlockCipherFactory;
00146 };
00147
00148 #endif // _AP4_ISMACRYP_H_