There is a subtle difference between the 2 implementations for a Montgomery curve defined from the 2 following links
A = X2+Z2 AA = A^2 B = X2-Z2 BB = B^2 E = AA-BB C = X3+Z3 D = X3-Z3 DA = D*A CB = C*B X5 = (DA+CB)^2 Z5 = X1*(DA-CB)^2 X4 = AA*BB Z4 = E*(BB+a24*E)
A = x_2 + z_2 AA = A^2 B = x_2 - z_2 BB = B^2 E = AA - BB C = x_3 + z_3 D = x_3 - z_3 DA = D * A CB = C * B x_3 = (DA + CB)^2 z_3 = x_1 * (DA - CB)^2 x_2 = AA * BB z_2 = E * (AA + a24 * E)
This AA / BB change on the last line does affect the result of a point multiplication with same input parameters.
Is there a reason for that difference ?