mirror of
https://github.com/qrtc/ffmpeg-dev-go.git
synced 2025-10-22 06:59:23 +08:00
2023-10-24 21:24:55 CST W43D2
This commit is contained in:
61
avutil_xtea.go
Normal file
61
avutil_xtea.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package ffmpeg
|
||||
|
||||
/*
|
||||
#include <libavutil/xtea.h>
|
||||
*/
|
||||
import "C"
|
||||
import "unsafe"
|
||||
|
||||
type AVXTEA C.struct_AVXTEA
|
||||
|
||||
// Custom: GetKey gets `AVXTEA.key` value.
|
||||
func (dct *AVXTEA) GetKey() []uint32 {
|
||||
return unsafe.Slice((*uint32)(&dct.key[0]), 16)
|
||||
}
|
||||
|
||||
// Custom: SetKey sets `AVXTEA.key` value.
|
||||
func (dct *AVXTEA) SetKey(v []uint32) {
|
||||
for i := 0; i < FFMIN(len(v), 16); i++ {
|
||||
dct.key[i] = (C.uint32_t)(v[i])
|
||||
}
|
||||
}
|
||||
|
||||
// Custom: GetKeyAddr gets `AVXTEA.key` address.
|
||||
func (dct *AVXTEA) GetKeyAddr() **uint32 {
|
||||
return (**uint32)(unsafe.Pointer(&dct.key))
|
||||
}
|
||||
|
||||
// AvXteaAlloc allocates an AVXTEA context.
|
||||
func AvXteaAlloc() *AVXTEA {
|
||||
return (*AVXTEA)(C.av_xtea_alloc())
|
||||
}
|
||||
|
||||
// AvXteaInit initializes an AVXTEA context.
|
||||
func AvXteaInit(ctx *AVXTEA, key []uint8) {
|
||||
if len(key) < 16 {
|
||||
panic("key len < 16")
|
||||
}
|
||||
C.av_xtea_init((*C.struct_AVXTEA)(ctx), (*C.uint8_t)(&key[0]))
|
||||
}
|
||||
|
||||
// AvXteaLeInit initializes an AVXTEA context.
|
||||
func AvXteaLeInit(ctx *AVXTEA, key []uint8) {
|
||||
if len(key) < 16 {
|
||||
panic("key len < 16")
|
||||
}
|
||||
C.av_xtea_le_init((*C.struct_AVXTEA)(ctx), (*C.uint8_t)(&key[0]))
|
||||
}
|
||||
|
||||
// AvXteaCrypt encrypts or decrypts a buffer using a previously initialized context,
|
||||
// in big endian format.
|
||||
func AvXteaCrypt(ctx *AVXTEA, dst, src *uint8, count int32, iv *uint8, decrypt int32) {
|
||||
C.av_xtea_crypt((*C.struct_AVXTEA)(ctx), (*C.uint8_t)(dst), (*C.uint8_t)(src),
|
||||
(C.int)(count), (*C.uint8_t)(iv), (C.int)(decrypt))
|
||||
}
|
||||
|
||||
// AvXteaLeCrypt encrypts or decrypts a buffer using a previously initialized context,
|
||||
// in little endian format.
|
||||
func AvXteaLeCrypt(ctx *AVXTEA, dst, src *uint8, count int32, iv *uint8, decrypt int32) {
|
||||
C.av_xtea_le_crypt((*C.struct_AVXTEA)(ctx), (*C.uint8_t)(dst), (*C.uint8_t)(src),
|
||||
(C.int)(count), (*C.uint8_t)(iv), (C.int)(decrypt))
|
||||
}
|
Reference in New Issue
Block a user